RediSearch icon indicating copy to clipboard operation
RediSearch copied to clipboard

Add weighting for numericFields

Open razzeee opened this issue 2 years ago • 4 comments

It would be nice to implement search, which can weight NumericFields.

In our case, we're building an appstore like application and want to give heigher ratings to apps, that have more downloads. But if we only by downloads, we end up loosing the weighting from the search and irrelevant apps, with many apps end up dominating the search results.

razzeee avatar Mar 08 '22 13:03 razzeee

Notice when you add a document you can also set its SCORE, if the SCORE will be relative to the downloads I think you'll be able to achieve what you're trying to achieve.

Check SCORE_FIELD in FT.CREATE documentation.

gkorland avatar Mar 08 '22 14:03 gkorland

Seems like this is not supported by redis-py via create_index? https://redis-py.readthedocs.io/en/stable/_modules/redis/commands/search/commands.html?highlight=score#

razzeee avatar Mar 08 '22 22:03 razzeee

@razzeee you can achieve this with FT.AGGREGATE. Use APPLY with whatever formula you wish and then sort by the result.

ashtul avatar Mar 09 '22 14:03 ashtul

I'm not sure how to get the weight or the score on aggregate, to be able to mash that up with a weighting of the downloads. And for the weighting I would need the max downloads, which doesn't seem to be a thing via apply as far as I tested/found docs?

.apply(downloads_last_month_max="MAX(downloads_last_month)")

razzeee avatar Mar 10 '22 00:03 razzeee