comparison src/goodjava/lucene/queryparser/GoodQueryParser.java @ 1619:83caee2ed4ad

Lucene.escape
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 25 Jul 2021 18:50:14 -0600
parents 45e42f403fb3
children a9591906e608
comparison
equal deleted inserted replaced
1618:a37ffe2d1b14 1619:83caee2ed4ad
17 17
18 public static Query parseQuery(FieldParser fieldParser,String query) throws ParseException { 18 public static Query parseQuery(FieldParser fieldParser,String query) throws ParseException {
19 return new GoodQueryParser(fieldParser,query).parseQuery(); 19 return new GoodQueryParser(fieldParser,query).parseQuery();
20 } 20 }
21 21
22 public static String quote(String s) { 22 public static String escape(String s) {
23 s = s.replace("\\","\\\\"); 23 s = s.replace("\\","\\\\");
24 s = s.replace("\b","\\b"); 24 s = s.replace("\b","\\b");
25 s = s.replace("\f","\\f"); 25 s = s.replace("\f","\\f");
26 s = s.replace("\n","\\n"); 26 s = s.replace("\n","\\n");
27 s = s.replace("\r","\\r"); 27 s = s.replace("\r","\\r");
28 s = s.replace("\t","\\t"); 28 s = s.replace("\t","\\t");
29 s = s.replace("\"","\\\""); 29 s = s.replace("\"","\\\"");
30 return "\""+s+"\""; 30 return s;
31 } 31 }
32 32
33 public static Sort parseSort(FieldParser fieldParser,String sort) throws ParseException { 33 public static Sort parseSort(FieldParser fieldParser,String sort) throws ParseException {
34 return new GoodQueryParser(fieldParser,sort).parseSort(); 34 return new GoodQueryParser(fieldParser,sort).parseSort();
35 } 35 }
192 private String Field() throws ParseException { 192 private String Field() throws ParseException {
193 parser.begin(); 193 parser.begin();
194 String match = Unquoted(NOT_IN_FIELD); 194 String match = Unquoted(NOT_IN_FIELD);
195 if( match.length()==0 ) 195 if( match.length()==0 )
196 return parser.failure((String)null); 196 return parser.failure((String)null);
197 match = StringFieldParser.escape(this,match); 197 match = StringFieldParser.unescape(this,match);
198 return parser.success(match); 198 return parser.success(match);
199 } 199 }
200 200
201 private String Quoted() throws ParseException { 201 private String Quoted() throws ParseException {
202 parser.begin(); 202 parser.begin();