I'm using elasticsearch in a NodeJS project, which is breaking upon entering one of the Lucene keywords into the search box. I'm looking for a simple implementation to escape their special characters. Is regex the best way? I've been fiddling with the regex for a bit now, and felt as if there were probably others that have already gone through this process.
Just needed to fiddle more.
var escaped = query.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"])/g, "\\$1");
Globally replace all instances of the chars lucene would yell about with their escaped version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With