Skip to content

Instantly share code, notes, and snippets.

@sam
Created August 5, 2014 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam/0f3a2210eca47b0dfb55 to your computer and use it in GitHub Desktop.
Save sam/0f3a2210eca47b0dfb55 to your computer and use it in GitHub Desktop.
Escape all in String
object Lucene {
object Escape extends (String => String) {
private val prefix: Char => PartialFunction[Char, String] = c => { case `c` => s"\\$c" }
private val escapist: PartialFunction[Char, String] = prefix('\\') orElse
prefix('+') orElse
prefix('-') orElse
prefix('!') orElse
{ case c => s"$c" }
def apply(s: String): String = s map(escapist) mkString
}
}
@sam
Copy link
Author

sam commented Aug 5, 2014

Just looking for a nice way to implement lucene.QueryParserUtil.escape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment