use of org.apache.lucene.search.TermRangeQuery in project jackrabbit by apache.
the class RangeQuery method rewrite.
/**
* Tries to rewrite this query into a standard lucene RangeQuery.
* This rewrite might fail with a TooManyClauses exception. If that
* happens, we use our own implementation.
*
* @param reader the index reader.
* @return the rewritten query or this query if rewriting is not possible.
* @throws IOException if an error occurs.
*/
public Query rewrite(IndexReader reader) throws IOException {
if (transform == TRANSFORM_NONE) {
TermRangeQuery stdRangeQueryImpl = new TermRangeQuery(lowerTerm.field(), lowerTerm.text(), upperTerm.text(), inclusive, inclusive);
stdRangeQueryImpl.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
try {
stdRangeQuery = stdRangeQueryImpl.rewrite(reader);
return stdRangeQuery;
} catch (BooleanQuery.TooManyClauses e) {
log.debug("Too many terms to enumerate, using custom RangeQuery");
// failed, use own implementation
return this;
}
} else {
// term enum
return this;
}
}
use of org.apache.lucene.search.TermRangeQuery in project neo4j by neo4j.
the class LuceneDocumentStructureTest method shouldBuildRangeSeekByStringQueryForStrings.
@Test
void shouldBuildRangeSeekByStringQueryForStrings() {
// given
TermRangeQuery query = (TermRangeQuery) LuceneDocumentStructure.newRangeSeekByStringQuery("foo", false, null, true);
// then
assertEquals("string", query.getField());
assertEquals("foo", query.getLowerTerm().utf8ToString());
assertFalse(query.includesLower());
assertNull(query.getUpperTerm());
assertTrue(query.includesUpper());
}
Aggregations