Query DSL: queryString - allow to escape the string (should be on by default), closes #41.

This commit is contained in:
kimchy 2010-02-24 22:00:03 +02:00
parent bcc52a0173
commit c7389df8e0
1 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,7 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength; int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;
int phraseSlop = 0; int phraseSlop = 0;
float boost = 1.0f; float boost = 1.0f;
boolean escape = true;
Analyzer analyzer = null; Analyzer analyzer = null;
String currentFieldName = null; String currentFieldName = null;
@ -101,6 +102,8 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
lowercaseExpandedTerms = token == JsonToken.VALUE_TRUE; lowercaseExpandedTerms = token == JsonToken.VALUE_TRUE;
} else if ("enablePositionIncrements".equals(currentFieldName)) { } else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = token == JsonToken.VALUE_TRUE; enablePositionIncrements = token == JsonToken.VALUE_TRUE;
} else if ("escape".equals(currentFieldName)) {
escape = token == JsonToken.VALUE_TRUE;
} }
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) { } else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("fuzzyMinSim".equals(currentFieldName)) { if ("fuzzyMinSim".equals(currentFieldName)) {
@ -123,6 +126,8 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
lowercaseExpandedTerms = jp.getIntValue() != 0; lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("enablePositionIncrements".equals(currentFieldName)) { } else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0; enablePositionIncrements = jp.getIntValue() != 0;
} else if ("escape".equals(currentFieldName)) {
escape = jp.getIntValue() != 0;
} }
} }
} }
@ -142,6 +147,10 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
queryParser.setFuzzyPrefixLength(fuzzyPrefixLength); queryParser.setFuzzyPrefixLength(fuzzyPrefixLength);
queryParser.setPhraseSlop(phraseSlop); queryParser.setPhraseSlop(phraseSlop);
if (escape) {
queryString = QueryParser.escape(queryString);
}
try { try {
Query query = queryParser.parse(queryString); Query query = queryParser.parse(queryString);
query.setBoost(boost); query.setBoost(boost);