Util Method For Lucene Escape
See original GitHub issueOften I find myself escaping the queries prior to executing them. I was using lucene-escape-query, but realized it isn’t quite right. I was going to create a pull request for that repo, but it seems like such a common thing that it would be beneficial to be included in this client library.
How are others handling this right now? Is there existing way or another package util people are using to do this?
What I was thinking is a simple util method as follows could be added to this client library…
// Based on https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-query-string-query.html#_reserved_characters
// TODO: This might not be exactly right
function escape (query) {
return query.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"\/])/g, "\\$1");
}
Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:23 (11 by maintainers)
Top Results From Across the Web
QueryParserUtil (Lucene 3.0.3 API)
This class defines utility methods to (help) parse query strings into Query objects ... that TextParser expects to be escaped are escaped by...
Read more >how can i escape a group of special characters in java in one ...
i am having problem escaping these characters because they are too many and if i use the String.replaceAll() method, i'll just end up...
Read more >org.apache.lucene.queryparser.flexible.standard ... - Tabnine
Returns a String where those characters that TextParser expects to be escaped are escaped by a preceding \ . Popular methods of QueryParserUtil....
Read more >KeywordsUtil (Liferay 6.1.2-ce-ga3 API)
com.liferay.util.lucene. Class KeywordsUtil ; escape · text) ; toFuzzy · keywords) ; toWildcard · keywords) ...
Read more >org.apache.lucene.queryparser.classic.QueryParserBase ...
This page shows Java code examples of org.apache.lucene.queryparser.classic.QueryParserBase#escape.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a lot, @spalger. You’ve given me lots of food for thought 😄
I still need to use the query string for now, because the API doesn’t receive the filters separated like that, but inside a
q
parameter. However, I’ll probably start adding those filters explictly as API parameters, then your suggestion will come in handy 👍Done simply with lucene by using :