Reputation: 232
I'm building a filter page, with facets etc, which works as it should. Now the our customer has a request to, basically "Be able to decide which sorting the items comes out in". Each product is decorated with a Product Display Order, and is in a Product Line.
We got these example Product Display Orders: 1. Featured Item 2. Core Item 3. Spare Part 4. Utility
And these Product Lines: 1. Hammers 2. Saw 3. Wood
and the sorting is like this: Sorting should firstly be based on Product Display Orders, secondly by product lines, thirdly Alphabetically. So all products which is a Featured Item is listed first, and all these Featured Items is then sorted by their product line, and if some product are in the same Featured Item and Product Line, then its alphabetically.
The challenge is: I can't just get the sorting of Product Display order items and product lines as a number on the product, i only got a name/id.
We've thought of Boosting based on if the product are in the different categories, but it seems a bit messy.
OR
See if it possible to have some logic in the Sorting. Sort by productDisplayOrder: 1. featured, 2. core Item ... Then by ProductLines: 1. Hammers, 2. Saw ... Then by Name DESC.
Which way is the best way to have this sorting, is it possible to give this logic to elastic, if it is a match and then sort it. Or are we needed to twist the boosts of product?
Hopefully this makes sense for you. Thanks in advance! :)
Upvotes: 1
Views: 352
Reputation: 3209
Option 1). Quickest/Best performing solution would be to create new/separate integer fields for productDisplayOrder
and ProductLine
and then use those in your sort criteria as described (after reindexing and validating the the data is indexed as expected).
Option 2) If you want more nuance than described (eg higher scoring matches can 'break through' the ordering ceiling described) then you can explore using a Function Score Query to implement a custom scoring strategy that takes productDisplayOrder
and ProductLine
into consideration in generating an overall match score.
Option 3). If you can't change the mapping and reindexing your data, you can use Script-Based Sorting to generate sorting values from the currently indexed productDisplayOrder/ProductLine text using a script (eg Groovy). Keep in mind that query performance will be worse than the first two options.
Upvotes: 3