react-typeahead icon indicating copy to clipboard operation
react-typeahead copied to clipboard

Sort results by relevance, not alphabetical order

Open yantakus opened this issue 10 years ago • 1 comments

Is there a way to sort results by relevance.

For example, if or options list is ['Canada', 'Abacan', 'Bolcan']. I type "Can" and see:

Abacan
Bolcan
Canada

But "Canada" is the most relevant result, because it starts with our inputValue.

I have a sort function to handle it:

arr.sort((a, b) => {
 if (a.indexOf(inputValue) > b.indexOf(inputValue)) return 1;
 else if (a.indexOf(inputValue) < b.indexOf(inputValue)) return -1;
 else return 0;
})

How can I implement it?

yantakus avatar Aug 21 '15 11:08 yantakus

:+1:

kjs3 avatar Mar 04 '16 00:03 kjs3