Is there a way to order search results by relevance to the search term?
For example, if I search “Dog”, the results will show an item with “Dog” in the title or keyword first and then all of the related items?
I hope this makes sense. Right now, seems like weighting, ASC and DSC are my only options?
Thanks in advance.
From what I understand, the Treepl search feature currently is not relevancy based.
All items found/matched are sorted as per the regular module sort methods we have available (as you’ve noted).
Perhaps a workaround could be to push the search results to a collection (instead of rendering them on the page). Then loop through the collection with Liquid, checking if the item’s name or keywords contain the search term.
If it does, render the item.
Else, capture the items to a capture
variable, adding items each time.
Then at the end of the loop, render the captured items.
This would effectively display the more relevant items first and all other items (without the search term in the name/keywords) after.
That is great, thank you. Unfortunately, my knowledge is very limited and I have no idea how to actually code that. I understand the terminology and basic operation, but no idea where to start or how to construct the loop.
This could be a good code snippet for the Treehouse Code library as others may find it useful too, so I’ll try and get something working and share it there.
Might be a week or 2 though…
1 Like
That would be absolutely amazing!!! I would be forever grateful. Thanks!!!