Sorting based on Relevancy Lucene Search | Community
Skip to main content
Level 3
February 8, 2023
Solved

Sorting based on Relevancy Lucene Search

  • February 8, 2023
  • 1 reply
  • 1270 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by nitesh_kumar-1

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/querybuilder-api.html?lang=en#fulltext-search-ordered-by-score 

 

Hope that helps!

 

Regards,

Nitesh

1 reply

nitesh_kumar-1
Adobe Employee
nitesh_kumar-1Adobe EmployeeAccepted solution
Adobe Employee
February 8, 2023

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/querybuilder-api.html?lang=en#fulltext-search-ordered-by-score 

 

Hope that helps!

 

Regards,

Nitesh

Level 4
February 27, 2023

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

Level 2
March 29, 2024

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.