Hi Everyone,
I am working on a project improving the search results for a "related stories" component in our news system. Here is a simplified query that shows how our current search functions.
path=/content/uc/news/articles
type=cq:Page
tagid.1_value=topics:student-experience
tagid.2_value=colleges:nursing
tagid.3_value=helpful-marketing:current-bearcats
tagid.4_value=helpful-marketing:student-life
tagid.property=@jcr:content/cq:tags
tagid.property.and=false
orderby=@jcr:content/dispDate
orderby.sort=desc
You can see the draw back, it's finding any stories with any tag and sorting by the display date, which means that a recent story that maybe only shares one tag would appear before another older story which could share all of the tags.
By changing the orderby parameter to jcr:score I can already see an improvement, however, since we have something like 32,000 news stories over 20+ years, basing it on just the score could lead to a situation where an older story that has the same score as a younger story would appear first.
path=/content/uc/news/articles
type=cq:Page
tagid.1_value=topics:student-experience
tagid.2_value=colleges:nursing
tagid.3_value=helpful-marketing:current-bearcats
tagid.4_value=helpful-marketing:student-life
tagid.property=@jcr:content/cq:tags
tagid.property.and=false
orderby=@jcr:score
orderby.sort=desc
So I have tried using multiple order by clauses, as show below, but this query behaves the same as my original search: stories with the more recent display date are always appearing first. Swapping hte 1_ and 2_ prefix has no effect
path=/content/uc/news/articles
type=cq:Page
tagid.1_value=topics:student-experience
tagid.2_value=colleges:nursing
tagid.3_value=helpful-marketing:current-bearcats
tagid.4_value=helpful-marketing:student-life
tagid.property=@jcr:content/cq:tags
tagid.property.and=false
2_orderby=@jcr:content/dispDate
2_orderby.sort=desc
1_orderby=@jcr:score
1_orderby.sort=desc
.
All of these have been tested in the querydebugger and the xpath generated does contain both order by statements. Swapping 1 and 2 does rearrange the xpath order by but has no effect on the results.
Is there an additional statement I can use to sort this the way I'm aiming to?
Alternatively, is there a better way to do a best match style search?
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @B_Stockwell
With AEM Queries, it is not possible to combine order column, you can have only one column for order predicate.
I think with custom code, you can order the the resultset before exporting.
e.g. https://stackoverflow.com/questions/22780347/order-by-based-on-a-expression
I am not sure if creating custom predicate would help here.
Views
Replies
Total Likes
@B_Stockwell
I was not able to understand what should be the sorting criteria for the results, Its a date? or number of tags?
Could you please explain what should be the ideal sorting order you are looking for?
This will help everyone here to provide correct guidance.
Views
Replies
Total Likes
HI Arun,
Apologies for not being clear.
We want more or less a "best match" that would first sort by # tags matched, then a subsort by display date
1st sort: # of matching tags desc
2nd sort: display date desc
For 7 stories:
I would like them to appear in this order in a query for tags a,b,c:
I have been toying with a lucene search for similarity with mixed results but will keep trying. Any advice is appreciated.
Views
Replies
Total Likes
Hi @B_Stockwell
With AEM Queries, it is not possible to combine order column, you can have only one column for order predicate.
I think with custom code, you can order the the resultset before exporting.
e.g. https://stackoverflow.com/questions/22780347/order-by-based-on-a-expression
I am not sure if creating custom predicate would help here.
Views
Replies
Total Likes
Ok, that clarifies some things. I was hoping this could all be done in the query so I could pass results directly to the front end, but sorting the result set is pretty easy. Thanks.
Views
Replies
Total Likes
Views
Likes
Replies