Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Sorting based on Relevancy Lucene Search

Avatar

Level 3

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

Hi @kirthi_murali ,

 

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

2 Replies

Avatar

Correct answer by
Employee

Hi @kirthi_murali ,

 

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 4

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