cancel
Showing results for 
Search instead for 
Did you mean: 

URGENT:Sorting Lucene result on tokenized property possible?

serverok
Champ in-the-making
Champ in-the-making
Hi all,
we have the problem with sorting of lucene search result by some properties which are indexed and tokenised.

What is the best/fastest method to correctly sort lucene results by properties that contain multiple tokens (http://lucene.apache.org/java/2_3_2/api/org/apache/lucene/search/Sort.html)? :
<index enabled="true">
   <atomic>true</atomic>
   <stored>false</stored>
   <tokenised>true</tokenised>
</index>

Is the only choice to sort "manually" in the web script after running the lucene query without sorting?

I tried use JS sort function:
var result = search.luceneSearch(query);
result.sort(Sorting);
….
function Sorting(a, b) {
   var x = a.properties['cm:title'];
   var y = b.properties['cm:title'];
   return ((x > y) ? 1 : -1);
}

but if we have a big list of content in lucene result (100, 200 and more) - then this section
var x = a.properties['cm:title'];
var y = b.properties['cm:title'];
very long working.

Also we have around 50 properties to each content (custom Model) - maybe this is the reason why we have so long going on reading the value of properties?

I would be very grateful for help in solving this problem.

Thank's,
Oleg Koval
17 REPLIES 17

kevinr
Star Contributor
Star Contributor
See the docs at the bottom of this section:
http://wiki.alfresco.com/wiki/3.2_JavaScript_API#Search_API

You can specify whatever store you like (including AVM), whatever language you like (say Lucene) and specify sorting also all together with the new API.

Kev

samuel_penn
Champ in-the-making
Champ in-the-making
Ah, right, so the search method on the AVM store itself is now effectively redundant. That works.

Thanks,
Sam.

samuel_penn
Champ in-the-making
Champ in-the-making
I've been playing a bit with 3.2 Preview, and the sort argument doesn't always seem to work. Sorting on name or modified time works fine, however sorting on title seems to sort by name.

I'm calling search.luceneSearch(query, "@cm:title", true);

Items are returned in cm:name order. Replacing "@cm:title" with "@cm:modified" returns them correctly in modified date order.

Has anyone else seen this?

Sam.

dwilson
Champ in-the-making
Champ in-the-making
Sam, perhaps there is a correlation with attribute tokenization?

samuel_penn
Champ in-the-making
Champ in-the-making
Sam, perhaps there is a correlation with attribute tokenization?

I don't think so, at least not unless tokenisation works a lot differently to my understanding of it. For example, the document with name "aidan-kingdom.yags" and title "Kingdom of Aidan" appears under the a's when documents are listed alphabetically.

Sam.

andy
Champ on-the-rise
Champ on-the-rise
Hi

Name is available tokenized and as an id, So sort works as you expect.
Title is only tokenised. So
"Kingdom of Aidan"
will most likely be two tokens
"Kingdom" and "Aidan"
It will sort by the lowest token.
It has nothing to do with name.

Change the default model and reindex if you do nto want the default behaviour.
Title is ML text and so will order by locale - depending on what does have properties in the locale …

Andy

samuel_penn
Champ in-the-making
Champ in-the-making
Okay, that makes sense from a technical perspective. I'd have to say though, I can't think of any situation where anyone would want sorting to actually behave like this (at least, not on an attribute such as cm:title).

I've changed the code to sort the results in Javascript, which seems safer than changing the default model.

Thanks,
Sam.

kbootz
Champ in-the-making
Champ in-the-making
so has there been any resolution to this issue? From what i've read and seen so far, if the sorted column contains multiple tokens then the result is inconsistent and a manual javascript exposed java backed sorting approach seems to be recommened(?)

OR

has this been corrected in the new 3.2 enterprise release so q query with a sorted multiple token field is sorted?

thanks

PS. we're using 3.2 community build 2039, schema 2019 but have purchased the enterprise 3.2 awaiting installation