Skip to content

Commit

Permalink
Query DSL: queryString - allow to escape the string (should be on by …
Browse files Browse the repository at this point in the history
…default), closes #41.
  • Loading branch information
kimchy committed Feb 24, 2010
1 parent bcc52a0 commit c7389df
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -70,6 +70,7 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;
int phraseSlop = 0;
float boost = 1.0f;
boolean escape = true;
Analyzer analyzer = null;

String currentFieldName = null;
Expand Down Expand Up @@ -101,6 +102,8 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
lowercaseExpandedTerms = token == JsonToken.VALUE_TRUE;
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = token == JsonToken.VALUE_TRUE;
} else if ("escape".equals(currentFieldName)) {
escape = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("fuzzyMinSim".equals(currentFieldName)) {
Expand All @@ -123,6 +126,8 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0;
} else if ("escape".equals(currentFieldName)) {
escape = jp.getIntValue() != 0;
}
}
}
Expand All @@ -142,6 +147,10 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
queryParser.setFuzzyPrefixLength(fuzzyPrefixLength);
queryParser.setPhraseSlop(phraseSlop);

if (escape) {
queryString = QueryParser.escape(queryString);
}

try {
Query query = queryParser.parse(queryString);
query.setBoost(boost);
Expand Down

0 comments on commit c7389df

Please sign in to comment.