-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Custom search separator #424
Conversation
@@ -396,9 +396,9 @@ class Chosen extends AbstractChosen | |||
if regex.test option.html | |||
found = true | |||
results += 1 | |||
else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0 | |||
else if (@search_separator.test and @search_separator.test(option.html)) or option.html.indexOf(@search_separator) >= 0 or option.html.indexOf("[") == 0 |
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.
If we're testing based on the regex, is there a reason to also check indexOf as well?
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.
Will running test repeatedly totally kill performance on very large selects (with at least several hundred elements)?
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.
My intention here was to support both string separators and regex separators. So, the tests are:
Is this a regex (@search_separator.test
) and does it match (@search_separator.test(option.html)
)?
or
Is this a string match (option.html.indexOf(@search_separator) >= 0
)
or
I'm not actually sure, this test was already here. (option.html.indexOf("[") == 0
)
Later on I use @search_separator
again as an argument to .split()
, but that takes strings and regexes.
I like the idea of this a lot, but wonder about performance of the newly introduced regex. |
See my above comment on the I haven't tried the regex option on a long select, I'll test out the performance and get back to you. |
Tested with 999 options, search_separator set to I stuck my test page in a gist if you want to test it for yourself: https://gist.github.com/49f6fbe128c878e804c4. |
This is a month old, any way to get it merged in? |
One more bump. |
Having a custom search separator would also solve the #1063 (words with quotes or parenthesis) which was partially fixed by #212. While #212 (allow searching through the entire word) was a good feature it does not quite do the same thing as searching for words in quotes or parenthesis. It would be nice to be able to continue to search for full words but ignore specific characters. There is currently a line that ignores the square brackets "[]":
It wold be great to have either a custom search separator regex or another option for specifying the regex of characters to ignore (maybe default to /[|]/). |
Bumping this! :) |
In an effort to try and get Chosen's repository under control and to best serve the people who use the tool, we're closing pull requests that add new functionality. For the time being, we're only merging bug fixes and functionality changes that are inline with Chosen's current scope. This doesn't mean we won't ever consider this functionality, but it does mean that we're being realistic about the time constraints the project maintainers have to give to this project. Sorry this has sat open so long @xcolour. The hope is that by getting things under control, we can get to a place in the future where we can once again start adding new functionality (at which point we'd come back to closed PRs like this). Thanks for your patience and understanding! |
This patch makes the token used in search configurable and falls back on current token (" ") if not set.
In my project, I have a list filled with semi-hierarchical options that might look like:
And I'd like to be able to search for "cpu" and get the relevant entries.
This patch allows me to initialize a chosen field with
And get the desired behavior.
The second commit also enables the use of regexes as the separator. I find this very useful for defining multiple characters to tokenize on (e.g. make three tokens out of "foo:bar-baz" with
/:|-/
).