Search in sources :

Example 36 with TermRangeQuery

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;
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery)

Example 37 with TermRangeQuery

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());
}
Also used : TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Test(org.junit.jupiter.api.Test)

Aggregations

TermRangeQuery (org.apache.lucene.search.TermRangeQuery)37 BooleanQuery (org.apache.lucene.search.BooleanQuery)17 BytesRef (org.apache.lucene.util.BytesRef)15 TermQuery (org.apache.lucene.search.TermQuery)14 Query (org.apache.lucene.search.Query)13 Term (org.apache.lucene.index.Term)10 IndexSearcher (org.apache.lucene.search.IndexSearcher)10 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)8 Document (org.apache.lucene.document.Document)7 BoostQuery (org.apache.lucene.search.BoostQuery)6 IndexReader (org.apache.lucene.index.IndexReader)5 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)5 ScoreDoc (org.apache.lucene.search.ScoreDoc)5 TextField (org.apache.lucene.document.TextField)4 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)4 PhraseQuery (org.apache.lucene.search.PhraseQuery)4 PrefixQuery (org.apache.lucene.search.PrefixQuery)4 RegexpQuery (org.apache.lucene.search.RegexpQuery)4 Map (java.util.Map)3 IndexWriter (org.apache.lucene.index.IndexWriter)3