cancel
Showing results for 
Search instead for 
Did you mean: 

Sort by title using lucene searchs

gabriel_g
Champ in-the-making
Champ in-the-making
Hello all,

I would like to know Whan I have to do for sorting the query results by title.

I've read that I'ts imposible to sort by tokenised properties but it must be done by other way.

I've tryed creating a new property with tokenised=false and type=d:text (I've tryed with type=d:mltext as well) and set that property from the title but it doesn't work…

Can anyone give me a hint or tell me how to do that?

Many thanks.
6 REPLIES 6

abarisone
Star Contributor
Star Contributor

gabriel_g
Champ in-the-making
Champ in-the-making
Hello,
you can find clues about sorting here http://wiki.alfresco.com/wiki/Search#Queries_that_sort and here http://wiki.alfresco.com/wiki/Search#Queries_that_sort
It may be useful also this http://wiki.alfresco.com/wiki/Full_Text_Search_Query_Syntax#JavaScript

Regards,
Andrea

I've read and use this way of querying but the problem still persisting… The matter is the title, that has different behaviour than name or another numeric field.

Anyway, thank you for your reply.

gabriel_g
Champ in-the-making
Champ in-the-making
Hello all,

I would like to know Whan I have to do for sorting the query results by title.

I've read that I'ts imposible to sort by tokenised properties but it must be done by other way.

I've tryed creating a new property with tokenised=false and type=d:text (I've tryed with type=d:mltext as well) and set that property from the title but it doesn't work…

Can anyone give me a hint or tell me how to do that?

Many thanks.

abarisone
Star Contributor
Star Contributor
But you're receiving an exception or the results are not sorted?
Could you please provide the code snippet you're using for the query?

Regards,
Andrea

gabriel_g
Champ in-the-making
Champ in-the-making
But you're receiving an exception or the results are not sorted?
Could you please provide the code snippet you're using for the query?

I'm receiving the results unsorted, and this only happen with that property and works properly with name, dates and integers (at least with what I've tried).

The code is quite simple:


var sortName ={
   column: "@cm:title",
   ascending: true
};

var def ={
   query: query,
   language: "Lucene",
   sort: [sortName]
};

var nodes = search.query(def);

billerby
Champ on-the-rise
Champ on-the-rise
Which API are you using?

With javascript:
quoted from wiki below:
Array luceneSearch(string query, string sortColumn, boolean asc)
Returns an array of ScriptNode satisfying the search criteria sorted by the specified sortColumn (the property name to sort on) and asc (true => ascending order, false => descending order). For example var nodes = search.luceneSearch("TEXT:alfresco", "@cm:modified", false);

If you are using java you can use the addSort on the SearchParamenters.

/Erik