Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select2 sort for teams is not stable, leading to inconsistent typeahead suggestions #56

Open
jdharms opened this issue Oct 31, 2014 · 2 comments

Comments

@jdharms
Copy link
Collaborator

jdharms commented Oct 31, 2014

The compare routine passed to the sort function for the Select2 fields on our submit ballot page returns where in the string the first instance of the search sequence appears. On Safari (and I believe Internet Explorer) JavaScript's sort function is stable, and provides "good" results. On Chrome, Texas Southern appears before Texas when searching.

I believe the correct fix here is to return the difference in IDs if the location of the query strings is the same.

@yeldarby
Copy link

I'm not sure what you mean by "difference in IDs" but I'd recommend using Levenshtein distance as the "tie breaker"; it's fairly standard.

A JavaScript version included in the underscore.string library if you want to use that as a reference or include that library: https://github.com/epeli/underscore.string/blob/master/levenshtein.js

@jdharms
Copy link
Collaborator Author

jdharms commented Dec 22, 2014

Right now we filter teams that have the search string in them, sorted by
position where that substring appears. That doesn't specify a sort order
for Texas and Texas Southern when the search string is Texas. Different
JavaScript implementations have different sort characteristics, some are
stable and some aren't.

Using Levenshtein distance ended up producing some weird results that I
can't really remember right now. Feel free to try it out again. If you need
any help getting a dev environment set up, file issues and we'll add to the
readme where appropriate.

The issue here is just to get behavior consistent across browsers and not
implementation dependent.

On Monday, December 22, 2014, Brad Dwyer [email protected] wrote:

I'm not sure what you mean by "difference in IDs" but I'd recommend using
Levenshtein distance as the "tie breaker"; it's fairly standard.

A JavaScript version included in the underscore.string library if you
want to use that as a reference or include that library:
https://github.com/epeli/underscore.string/blob/master/levenshtein.js


Reply to this email directly or view it on GitHub
#56 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants