Open ghost opened 4 years ago
Hi so to change the order will be relatively easy. One option is to change options.sorter.
Default sorter is here and proceed to sort by score then name (or a custom sortkey) https://github.com/jeancroy/FuzzySearch/blob/6a7d5530d2000087f26071ba4adf7a025ec7ef13/src/output.js#L189
Inside the sorter you can access original item as a.item and b.item
So one option then is to sort by priority first then sort by score (when priority is the same) To do this, you can get inspiration from the logic already here that sort by score first then by name of the item.
You may also be able to create an importance criteria and use something like this.
d = b.score * b.item.importance - a.score * a.item.importance
.
For the grouping I'm not certain where to go. I imagine you want to score if the group to be best score among it's items. One hint I can give is that this will allow to output full information:
https://github.com/jeancroy/FuzzySearch#get-score-detail-searchresult-object
If I had to implement the feature I'd probably do something like this
have groupKey as an option (default as none = turn off groupkey )
Insert self about here (only do something if groupKey has been set, group replace existing output map logic) https://github.com/jeancroy/FuzzySearch/blob/master/src/search.js#L48
GroupingFunction:
Setup dictionary of group key => group object.
Setup list of ungrouped items.
For each result, get group key.
If no grouping key set, apply output transform and add to ungrouped list (in a way that preserve item ordering).
If group key is defined for the item:
Copy the dictionary into an array, (sort the array? or already sorted?)
Append the ungrouped items at the end of the group array ?
Hi Jean, thank you for Fuzzysearch, it's excellent. My feed contains categories and products, I'm wondering if...
1) I can give a higher score/priority to specific items, so they appear before anything else. 2) I can group the results, so that matched categories always appear before matched products.
My feed looks like this...
Note, I'm using Twitter typeahead. Grateful for any advice you can give. Phil