arthurio / fastapi-filter

Filter and order your endpoints
https://fastapi-filter.netlify.app/
MIT License
222 stars 30 forks source link

Order by best match when searching #433

Open gehal4 opened 1 year ago

gehal4 commented 1 year ago

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

github-actions[bot] commented 10 months ago

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.

foarsitter commented 10 months ago

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!

github-actions[bot] commented 7 months ago

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] commented 1 month ago

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.