Expand my Community achievements bar.

Search "Boosting" (or Similarity) in Query Builder?

Avatar

Level 5

I am using QueryBuilder for search on my website, which is on AEMaaCS 6.5 2023.01

 

TLDR: Is there a way to query for pages and apply boosting based on tags? 

 

For example, I am trying to find 'related' pages to a blog post page.  The blog post has 3 tags associated with it.  I would like to search for all blog posts, and boost results that have any one of the tags to the top.  I would order the results by relevance, and then by date, and take the first 4 returned.  In some platforms this is called 'boosting', but I couldn't find anything like this in the AEM documentation.  I believe Lucene supports boosting using a "^" caret, for instance: Apache Lucene - Query Parser Syntax 

4 Replies

Avatar

Community Advisor

Hi @dylanmccurry 

For boosting search results based on a specific field, you can do the following

we have a property called boost -> set it to a higher value say 2.0 (on tags field in this case) within the index definition. 

For example,

  • for a query like the below, OOTB cqPageLucene is used
path=/content/we-retail
type=cq:Page
fulltext=biking
p.limit=-1
  • In this path - /oak:index/cqPageLucene/indexRules/cq:Page/properties , create property for cq:tags and set the following properties (in addition to the mandatory properties - name, propertyIndex)
    • nodeScopeIndex -> true
    • analyzed -> true
    • boost -> 2.0
  • Reindex post the index definition update

 

Avatar

Level 5

Thanks.  How do you reindex?

 

And would this work if I am searching for: TagA or TagB or TagC, and I want results that have all 3 tags to come before results that have any of the two tags, which come before results that have just one tag, etc?

Avatar

Community Advisor

@dylanmccurry , you can use

path=/content/we-retail
type=cq:Page
group.1_property=jcr:content/@cq:tags
group.1_property.value=we-retail:apparel/pants
group.2_property=jcr:content/@cq:tags
group.2_property.value=we-retail:apparel/shirt
group.p.or=true
p.limit=-1

 

A short article of 

can be found here Find all AEM Pages with Tags with Query Builder API - Sourced Code

Avatar

Level 5

This seems to work, but ordering is not working as expected.  Each hit in the results has a score of 0.01.  How can we influence the score correctly so that we can sort by items which have more tags that overlap as opposed to fewer tags that overlap?

 

e.g., when I call `hit.getScore()` a value of 0.01 is returned for all hits.