Hello all,
I'm wondering if there's a way to sort on the Nth result.
My use case: show the most relevant item at the top and then from there show similar items starting from the cheapest item, so sorting by price. This can be done on the front end but ideally done via my API call to ES.
Any clues?
Cheers
Sounds like what you're describing is "pinned results"? If so, have you looked at Query Rules?
I haven't looked at it but looking at it now and it might do the trick because I can make sure the best match is pinned, assuming the sort filter will keep the pinned item intact in it's place, which seems like it.
Any other matches from the organic query will be returned below the pinned results.
Will give it a shot. Thanks @Sean_Story
After looking it at further, it seems I would need to pin a specific Id which would require for me to go through the list add the rules programmatically.
use case here: comparing products in one store to another. Find the same item and then similar ones ordered by price.
So I can go through all items first to make a rule on them before any user requests the comparison.
If I end up doing that, would my queries using the rule have better performance ? Just to know if it's worth it. It seems the query rule is still under the hood a query to be executed.
Edit. It seems that the limit of 1000 won't work as I would need to make this per item and there thousands of items .
use case here: comparing products in one store to another. Find the same item and then similar ones ordered by price.
This is helpful, and I think I hadn't understood your use case previously. Double checking my understanding now, is the expected user experience that the user selects a product from the other store, and this shows the alternatives? For this, I wouldn't suggest query rules, but just executing two queries. The first query should be an exact match type of query, where you know exactly what record should be returned (like, lookup by ID, grab the first result), and the second query is based off of metadata that's present in the first query's result (like search for other products based on the same keyword/description).
Or am I still misunderstanding? Like let's say the products you're comparing against are from Amazon - if the user just searches for "tshirts", Amazon will have a lot of hits, not just one. In this case, I'm not sure how you'd expect to group your results to compare multiple offerings from the other store agains "similar" products from this store.
Well It is like you described the first case but has some nuances.
I will be comparing grocery products.
Let's say you go to Store A inside my site, you add a can coca-cola. I will show you in real time the most matching item and similar item from Store B and C.
So today I achieved it with 1 query by query bool must should syntax and a filter to go through store B and C. Also I will show the user alternative items similar to the can of coca cola selected for example they selected the 300ml so first match for store B and C would be the 330ml can of cola and then alternatives from there could be cola could be other sodas from the same family.
It won't be based on user search, it will be based on user selection and that provides me the details I need to make it work in 1 query.
Hey @Sean_Story I was actually capable of fixing this by using field value factor.
Since the top result will have such a high score, a reciprocal function on the price will sort all results in a way that keeps the first item on top.
"functions": [
{"field_value_factor": {
"field": "price",
"factor": 2,
"modifier": "reciprocal",
"missing": 1
}}
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.