Dynamically Sort Per User

I would like to sort results based on user information, but not exclude results. This has led me to considering optionalFilters. However, the data I would like to sort is ordinal numeric. Thus I’d like to have it sort ascending/descending rather than on an exact value. However, it appears that comparisons cannot be used in optional filters. Is this correct?

Consider the data something like this:
Every time something is purchased we update the “purchases” facet to include age range data. So something like

purchases [
  'total': 15
  '0-17': 3,
  '17-25': 10
  '25+': 2
]

Taking into account the logged in user’s age I would like to promote items that have the highest purchase values for their age range.

Is there any way to accomplish this?

Thank you!!

Optional filters are more yes/no – so if you had a filter attribute called “popular-age-ranges” for each product, you could set an optionalFilter with the logged in users age range and products that include it would rank higher (and the ranking would continue to be based on purchase value).

You could do a second query against the index with a threshold around the particular age range. Something like…

index.search('query', {
  numericFilters: [
      'purchases.17-25 > 10'
  ]

You could wrap this in a searchMultipleIndices to get both results back at the same time and then combine them in the UI.

Thanks Chuck–I figured I would have to do something as you suggested with data pre-processing. The multi-search is an interesting suggestion. Though it would be difficult as the threshold could be a moving target per age range.
When the results are combined how are they sorted?

using searchMultipleIndices you get each result set separately in the response – so you can display them as such or you can combine them however you see fit when you display them in the front end.