Example usage for org.apache.lucene.search MultiTermQuery CONSTANT_SCORE_BOOLEAN_REWRITE

List of usage examples for org.apache.lucene.search MultiTermQuery CONSTANT_SCORE_BOOLEAN_REWRITE

Introduction

In this page you can find the example usage for org.apache.lucene.search MultiTermQuery CONSTANT_SCORE_BOOLEAN_REWRITE.

Prototype

RewriteMethod CONSTANT_SCORE_BOOLEAN_REWRITE

To view the source code for org.apache.lucene.search MultiTermQuery CONSTANT_SCORE_BOOLEAN_REWRITE.

Click Source Link

Document

Like #SCORING_BOOLEAN_REWRITE except scores are not computed.

Usage

From source file:org.apache.solr.legacy.TestNumericRangeQuery32.java

License:Apache License

/** test for both constant score and boolean query, the other tests only use the constant score mode */
private void testRange(int precisionStep) throws Exception {
    String field = "field" + precisionStep;
    int count = 3000;
    int lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);
    LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper,
            true, true);/* w  w  w.ja  va  2 s.  c om*/
    for (byte i = 0; i < 2; i++) {
        TopDocs topDocs;
        String type;
        switch (i) {
        case 0:
            type = " (constant score filter rewrite)";
            q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
            topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
            break;
        case 1:
            type = " (constant score boolean rewrite)";
            q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
            topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
            break;
        default:
            return;
        }
        ScoreDoc[] sd = topDocs.scoreDocs;
        assertNotNull(sd);
        assertEquals("Score doc count" + type, count, sd.length);
        Document doc = searcher.doc(sd[0].doc);
        assertEquals("First doc" + type, 2 * distance + startOffset,
                doc.getField(field).numericValue().intValue());
        doc = searcher.doc(sd[sd.length - 1].doc);
        assertEquals("Last doc" + type, (1 + count) * distance + startOffset,
                doc.getField(field).numericValue().intValue());
    }
}

From source file:org.apache.solr.legacy.TestNumericRangeQuery64.java

License:Apache License

/** test for constant score + boolean query + filter, the other tests only use the constant score mode */
private void testRange(int precisionStep) throws Exception {
    String field = "field" + precisionStep;
    int count = 3000;
    long lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);
    LegacyNumericRangeQuery<Long> q = LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper,
            true, true);/*from  ww  w. j ava  2 s  .c o  m*/
    for (byte i = 0; i < 2; i++) {
        TopDocs topDocs;
        String type;
        switch (i) {
        case 0:
            type = " (constant score filter rewrite)";
            q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
            topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
            break;
        case 1:
            type = " (constant score boolean rewrite)";
            q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
            topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
            break;
        default:
            return;
        }
        ScoreDoc[] sd = topDocs.scoreDocs;
        assertNotNull(sd);
        assertEquals("Score doc count" + type, count, sd.length);
        Document doc = searcher.doc(sd[0].doc);
        assertEquals("First doc" + type, 2 * distance + startOffset,
                doc.getField(field).numericValue().longValue());
        doc = searcher.doc(sd[sd.length - 1].doc);
        assertEquals("Last doc" + type, (1 + count) * distance + startOffset,
                doc.getField(field).numericValue().longValue());
    }
}

From source file:org.codelibs.elasticsearch.index.query.support.QueryParsers.java

License:Apache License

public static MultiTermQuery.RewriteMethod parseRewriteMethod(@Nullable String rewriteMethod,
        @Nullable MultiTermQuery.RewriteMethod defaultRewriteMethod) {
    if (rewriteMethod == null) {
        return defaultRewriteMethod;
    }// w ww .  ja  v  a 2  s  .  c  o m
    if (CONSTANT_SCORE.match(rewriteMethod)) {
        return MultiTermQuery.CONSTANT_SCORE_REWRITE;
    }
    if (SCORING_BOOLEAN.match(rewriteMethod)) {
        return MultiTermQuery.SCORING_BOOLEAN_REWRITE;
    }
    if (CONSTANT_SCORE_BOOLEAN.match(rewriteMethod)) {
        return MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE;
    }

    int firstDigit = -1;
    for (int i = 0; i < rewriteMethod.length(); ++i) {
        if (Character.isDigit(rewriteMethod.charAt(i))) {
            firstDigit = i;
            break;
        }
    }

    if (firstDigit >= 0) {
        final int size = Integer.parseInt(rewriteMethod.substring(firstDigit));
        String rewriteMethodName = rewriteMethod.substring(0, firstDigit);

        if (TOP_TERMS.match(rewriteMethodName)) {
            return new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(size);
        }
        if (TOP_TERMS_BOOST.match(rewriteMethodName)) {
            return new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite(size);
        }
        if (TOP_TERMS_BLENDED_FREQS.match(rewriteMethodName)) {
            return new MultiTermQuery.TopTermsBlendedFreqScoringRewrite(size);
        }
    }

    throw new IllegalArgumentException("Failed to parse rewrite_method [" + rewriteMethod + "]");
}