lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd Nine <>
Subject escaping of queries with solr
Date Thu, 10 Feb 2011 21:27:18 GMT
Hi guys,
  We're migrating from Lucene to Solr.  We have a lot of existing code
that created queries in memory with Lucene.  Below is an example of such
a query.

		BooleanQuery query = new BooleanQuery();

		BooleanQuery inputTerms = new BooleanQuery();
		inputTerms.add(new TermQuery(new Term(FIELD_EMAIL, input)),

		String numeric = getNumericString(input);

		if (StringUtils.hasText(numeric)) {
			inputTerms.add(new TermQuery(new Term(FIELD_PHONE, numeric)),

		query.add(inputTerms, Occur.MUST);

		NumericRangeQuery time = NumericRangeQuery.newLongRange(
				FIELD_CREATETIME, null, endTime, true, true);

		query.add(time, Occur.MUST);

		return getResults(query, count);

As per an old thread in the mailing list, I can generally call
query.toString() which will generate a query I can send to solr.
However, we're getting some strings such as this.

phone_string_multi_index:6411122222) +rslved_string_index:false
+crttime_long_index:[* TO 1284093338200]':

Which will generate this error Encountered " "+" "+ "" at line 1, column

The cause is the "+6411122222".  

Is there an equivalent for building a query tree in the Solr4j client
that will properly escape the input sequence?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message