Last active
September 5, 2017 02:09
-
-
Save aackerman/8835988 to your computer and use it in GitHub Desktop.
Escaping a Lucene query in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RE_ESCAPE_LUCENE = / | |
( [-+!\(\)\{\}\[\]^"~*?:\\\/] # A special character | |
| && # Boolean && | |
| \|\| # Boolean || | |
) | |
/x | |
"123-456-7890".gsub(RE_ESCAPE_LUCENE) { |m| "\\#{m}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment