-
Notifications
You must be signed in to change notification settings - Fork 548
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
How to escape a special character? #271
Comments
At the moment the search string does not provide support for escaping characters. This is something that I want to add at some point. In the mean time you can use idx.query(function (q) {
q.term("foo^")
}) |
Thanks @olivernn , I actually looked at that before but then I was stuck trying to get the best of both worlds, e.g. |
Everything that is possible with a search string is possible with the idx.query(function (q) {
q.term("n^2", { fields: ["title"] })
}) The documentation shows how to add fields, boosts etc. |
great, thanks @olivernn . Do you know how I can escape the wildcard |
Its not possible to escape the wildcard character at the moment, and I think it'll be a bit tricky to implement. I'll think about the best way to do so when implementing escape sequences in the search string, but "*" has special meaning in a number of places that might be harder to sidestep. |
The latest alpha (2.1.0-alpha.2) includes support for escape query characters, e.g "12:00pm" will do a search for "12:00pm" rather than complain about a missing field called "12". This does not include support for escaping asterisks "*", that requires some more fundamental changes that I'm not inclined to work on, yet. As ever, try it out and let me know any feedback. |
I've just published 2.1.0 which includes support for escaping special characters. |
Excuse me, but I couldn't find the instruction how to use escaping for special charactes, could you please point me. I try to search term "C#". But idx.query(function (q) {
q.term("C#")
}); didn't work. Thank you. |
I cannot find any instruction about escaping the modifiers as well. @olivernn Any updates? thanks. |
@wangpin34 I found this in our code, not sure where I got it from: str.replace(/[~^\-+]/g, (x) => `\\${x}`) |
e.g. Is it possible to search for the character '^' using the search method? I do not want it to be interpreted as a search modifier (boost).
The text was updated successfully, but these errors were encountered: