Skip to content

Instantly share code, notes, and snippets.

@aackerman
Last active September 5, 2017 02:09
Show Gist options
  • Save aackerman/8835988 to your computer and use it in GitHub Desktop.
Save aackerman/8835988 to your computer and use it in GitHub Desktop.
Escaping a Lucene query in Ruby
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