fastapi-filter icon indicating copy to clipboard operation
fastapi-filter copied to clipboard

Order by best match when searching

Open gehal4 opened this issue 2 years ago • 6 comments

The search option is really great, however would be nice to have a option to filter by best match. One option would offer the possibility to enable this feature like :

class Constants:
     # ....
     enable_search_weight: bool = False

In this case, when searching, it will apply an order on the weight of the search: one example for the weight is to sort by the length of the field(s) searched : https://stackoverflow.com/questions/15471718/how-to-sort-results-by-string-length-on-mongodb

gehal4 avatar Jul 25 '23 15:07 gehal4

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jan 12 '24 01:01 github-actions[bot]

It is easy to override the Filter.sort method and apply your custom sorting. I'm not familiar with mongodb but this looks promising: https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/control-text-search-results/

Don't forget to provide a PR when your implementation is ready!

foarsitter avatar Jan 12 '24 08:01 foarsitter

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 09 '24 01:04 github-actions[bot]