-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Added support for fuzzy word search #1037
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
Conversation
@@ -1,5 +1,8 @@ | |||
# Chosen | |||
|
|||
**Note:** This is an experimental fork implementing "fuzzy" word search (as introduced in [this issue](https://github.com/harvesthq/chosen/issues/858)). | |||
For the original Chosen plugin, check out https://github.com/harvesthq/chosen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shoud be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
the Prototype version should be updated as well. Both implementations should be kept in sync feature-wise |
@stof hey man, I've just updated the code with your recommendations! :) |
I tried your jquery file and on many case I had |
@p-j hey, man! I'm not being able to reproduce your problem. Could you provide an example? |
@eliasdorneles, I whas not able to repro with your script only. Sorry for the false alarm. |
@stof hey, man! Is there something else that is missing for this to go upstream? |
Just thought I should mention that I've been using this branch for a while now and it works really well. I, personally, haven't noticed anything wrong with it. It would be nice to have this in the core repository although I would imagine it would have to be behind a flag for backwards compatibility. |
This version is working great! |
I can't say when or if this would be merged, but can you please at least a.) rebase against master, and b.) squash this into one (or a few) logical commit(s) to remove a lot of the leftover dev-cycle cruft in the commits? Things like 5e809cb and d806b34 and d6f3a81 should be squashed out of the history. Directions here if you're unfamiliar. |
@tjschuck thank you for the directions -- I'm not familiar with rebase yet, I'll give a try. |
@tjschuck well, I was able to squash it into one commit only -- that should make the revision a bit easier. |
@eliasdorneles If you rebase against master, you should then be up to date with what's happened there. Looking at https://github.com/eliasdorneles/chosen/commits/master, it appears that you're still quite a bit behind. |
Well, I meant to say that it was not that simple to rebase because the upstream code had several conflicting changes that were made after my initial pull request, and I had't been able to keep up. |
Can someone please take a second look at this patch? |
startpos = text.toLowerCase().indexOf word | ||
while startpos >= 0 | ||
text = text.substr(0, startpos) + '<em>' + text.substr(startpos, word.length) + '</em>' + text.substr(startpos + word.length) | ||
startpos = text.toLowerCase().indexOf(word, startpos + highlight_offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you use startpos + highlight_offset + word.length
to start matching only at the end of the occurrence we just found ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is that it would require the word parts to be in the same order. You see, it supports queries like "state uni" giving as results "United States" and also "Florida State University" -- this is useful when the user is not much familiar with the option names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this startpos defined on this line is about searching the same word again later in the text, not about searching the next word.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, you're absolutely right -- sorry for my confusion! That makes sense, it should add word.length
to get the next match.
I think the highlighting logic is flawed if you are searching for |
regexAnchor = if @search_contains then "" else "^" | ||
regex = new RegExp(regexAnchor + escapedSearchText, 'i') | ||
zregex = new RegExp(escapedSearchText, 'i') | ||
words = searchText.toLowerCase().split(' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to filter empty strings out of the list of words (in case of several consecutive spaces) to avoid weird stuff in the highlighting.
@stof thanks for the review, man -- I'll try to fix these. |
@stof hey, man! I've added a new commit fixing the stuff you pointed out. Also, I've tested the behavior of the highlighting with the search queries you mentioned and they seemed to work fine.
What I found was:
If you really think it's worthwhile, I can try coming up with some algorithm to avoid the nested highlighting but as it doesn't affect the behavior, I hesitate to add more code to this with potentially more bugs -- it is simpler as it is. |
I tried implementing fuzzy search using a single regex, which works but then its not possible to highlight the matches. |
@koenpunt Before adding specs, it would be easier to merge the PR adding the runner first so that they can be used |
bump - what's up with this? Over a year old, lots of people want fuzzy search done right - will it appear in chosen master do you think, folks? |
I don't yet know if fuzzy filtering will ever get added to Chosen or not, but it seems #2599 is a more up-to-date version and I'm going to close this. Thanks @eliasdorneles and very sorry it took me THREE YEARS to do anything with this. |
Implemented "fuzzy" word search as presented in issue #858