Expand my Community achievements bar.

SOLVED

Sorting based on Relevancy Lucene Search

Avatar

Level 4

Hi all,

We have implemented Lucene full text search by implementing a query. Now we have this requirement to sort the results based on textual relevancy.

We would like to perform this sorting with highest being the maximum number of occurrences of the search keyword in the results obtained on fulltext search. 

We tried doing this through standard java string operations, but it takes a lot of time as the results are more.

Is there a possibility to do this using any available predicates in the query itself? Or is there any other way of doing this?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @pixislinger ,

 

Have you checked the scoring feature of JCR Queries? 

https://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-jcr-query-usecases.html#d0e3332 

 

It basically returns the results with a score for each row in the result set. The score contains a value that indicates a rating of how well the result node matches the query. A high value means a better matching than a low value

 

This score can be used for ordering the result. So in the query builder, you can add something like:-

orderby=@jcr:score

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/query-builder/quer... 

 

Hope that helps!

 

Regards,

Nitesh

View solution in original post

3 Replies

Avatar

Correct answer by
Employee Advisor

Hi @pixislinger ,

 

Have you checked the scoring feature of JCR Queries? 

https://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-jcr-query-usecases.html#d0e3332 

 

It basically returns the results with a score for each row in the result set. The score contains a value that indicates a rating of how well the result node matches the query. A high value means a better matching than a low value

 

This score can be used for ordering the result. So in the query builder, you can add something like:-

orderby=@jcr:score

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/query-builder/quer... 

 

Hope that helps!

 

Regards,

Nitesh

Avatar

Level 5

I am trying this, but the score is always 0.01.  What else is required?

Avatar

Level 2

Did you ever get an answer? I read another post that simply said that value is hard-coded in - but there was no explanation of why or how to get an actual real value.