Try our conversational search powered by Generative AI!

Sort By a Value Not in the Find Index?

Vote:
 

We're using Find to get personalized results for commerce products like so (psuedo-ish code for brevity) - 

var searchService = ITypeSearch<OurProductModel>();
searchService = searchService.For(term)//plus boosting, best bets, synonyms, etc
searchService = searchService.OrderBy(p => p.Code); //this is actually in a switch statement to allow the user to sort by item number, name, brand, etc
searchService = searchService.Skip(...).Take(...) //do skips and takes for paging
var results = searchService.Select(OurProductModel=> new ProductResultItem{//do the mappings}).GetResult();

As noted, we apply the OrderBy in a switch statement corresponding to the user choice. I want to add a new choice but the crux of the issue (I think) is that the new value to sort by is NOT in the index. We want to add a sort by price, however, in this B2B site prices vary by customer which means theoretically one product could literally have thousands of prices. We retrieve the price for the current user from an external service that sits behind a cache layer.

So, I guess the simple form of the question is, is there a way to apply an OrderBy for a value not in the index like:

searchService.OrderBy(p => _priceService.GetPrice(p.Code, currentUserAccountNumber));

Spoiler, I've tried this and while it executes, calls our price service, and does not error, it also does not sort.

#220947
Apr 08, 2020 22:33
Vote:
 

Hi Jason, 

I've been in a very similar situation on a previous project where we had potentially thousands of prices per sku. 

Although we weren't sorting by price, we were displaying pricing information in the search results, which we had to build into search results after getting the majority of the result content out of Find. 

Unfortunately I didn't find a way of doing this - if you had pricing tiers in place whereby you could store a reference to the tiered pricing and then sort by the customers own tier during sorting that could work but if its as random as the pricing we had in place on our own project I don't see a solution. 

As Find is built on top of Elasticsearch your search query will summount to a query in Elasticsearch which will need reference to a given field in the index. 

Only other alternative would be to get all the results and order the collection yourself in memory, but this itself may not be doable if the number of results is large - max results returned is 1000. 

Cheers!

Paul 

#220974
Edited, Apr 09, 2020 11:11
Vote:
 

Hey Paul.

Thanks for the thoughts! The pricing tiers idea gives me some thoughts - I think I need to get with the business to wrap my head around how their pricing structures work. That may be more reasonable to work into the index.

Thanks!

Jason

#220986
Apr 09, 2020 14:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.