Mercurial Hosting > luan
changeset 1619:83caee2ed4ad
Lucene.escape
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 25 Jul 2021 18:50:14 -0600 |
parents | a37ffe2d1b14 |
children | 99a8ac891914 |
files | src/goodjava/lucene/queryparser/GoodQueryParser.java src/goodjava/lucene/queryparser/StringFieldParser.java src/luan/modules/lucene/Lucene.luan |
diffstat | 3 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
diff -r a37ffe2d1b14 -r 83caee2ed4ad src/goodjava/lucene/queryparser/GoodQueryParser.java --- a/src/goodjava/lucene/queryparser/GoodQueryParser.java Mon Jun 14 18:45:17 2021 -0600 +++ b/src/goodjava/lucene/queryparser/GoodQueryParser.java Sun Jul 25 18:50:14 2021 -0600 @@ -19,7 +19,7 @@ return new GoodQueryParser(fieldParser,query).parseQuery(); } - public static String quote(String s) { + public static String escape(String s) { s = s.replace("\\","\\\\"); s = s.replace("\b","\\b"); s = s.replace("\f","\\f"); @@ -27,7 +27,7 @@ s = s.replace("\r","\\r"); s = s.replace("\t","\\t"); s = s.replace("\"","\\\""); - return "\""+s+"\""; + return s; } public static Sort parseSort(FieldParser fieldParser,String sort) throws ParseException { @@ -194,7 +194,7 @@ String match = Unquoted(NOT_IN_FIELD); if( match.length()==0 ) return parser.failure((String)null); - match = StringFieldParser.escape(this,match); + match = StringFieldParser.unescape(this,match); return parser.success(match); }
diff -r a37ffe2d1b14 -r 83caee2ed4ad src/goodjava/lucene/queryparser/StringFieldParser.java --- a/src/goodjava/lucene/queryparser/StringFieldParser.java Mon Jun 14 18:45:17 2021 -0600 +++ b/src/goodjava/lucene/queryparser/StringFieldParser.java Sun Jul 25 18:50:14 2021 -0600 @@ -31,7 +31,7 @@ return new WildcardQuery(new Term(field,wildcard)); if( query.endsWith("*") && !query.endsWith("\\*") ) return new PrefixQuery(new Term(field,query.substring(0,query.length()-1))); - query = escape(qp,query); + query = unescape(qp,query); PhraseQuery pq = new PhraseQuery(); try { TokenStream ts = analyzer.tokenStream(field,new StringReader(query)); @@ -55,12 +55,12 @@ } @Override public Query getRangeQuery(GoodQueryParser qp,String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) throws ParseException { - minQuery = minQuery.equals("*") ? null : escape(qp,minQuery); - maxQuery = maxQuery.equals("*") ? null : escape(qp,maxQuery); + minQuery = minQuery.equals("*") ? null : unescape(qp,minQuery); + maxQuery = maxQuery.equals("*") ? null : unescape(qp,maxQuery); return TermRangeQuery.newStringRange(field,minQuery,maxQuery,includeMin,includeMax); } - static String escape(GoodQueryParser qp,String s) throws ParseException { + static String unescape(GoodQueryParser qp,String s) throws ParseException { final char[] a = s.toCharArray(); int i, n; if( a[0] == '"' ) {
diff -r a37ffe2d1b14 -r 83caee2ed4ad src/luan/modules/lucene/Lucene.luan --- a/src/luan/modules/lucene/Lucene.luan Mon Jun 14 18:45:17 2021 -0600 +++ b/src/luan/modules/lucene/Lucene.luan Sun Jul 25 18:50:14 2021 -0600 @@ -59,7 +59,11 @@ double = NumberFieldParser.DOUBLE } -Lucene.quote = GoodQueryParser.quote +local escape = GoodQueryParser.escape +Lucene.escape = escape +function Lucene.quote(s) + return [["]]..escape(s)..[["]] +end local function get_file(f,name) type(f)=="table" or error(name.." must be table")