Search in sources :

Example 1 with ValueSourceRangeFilter

use of org.apache.solr.search.function.ValueSourceRangeFilter in project lucene-solr by apache.

the class DirectUpdateHandler2 method getQuery.

private Query getQuery(DeleteUpdateCommand cmd) {
    Query q;
    try {
        // move this higher in the stack?
        QParser parser = QParser.getParser(cmd.getQuery(), cmd.req);
        q = parser.getQuery();
        q = QueryUtils.makeQueryable(q);
        // Make sure not to delete newer versions
        if (ulog != null && cmd.getVersion() != 0 && cmd.getVersion() != -Long.MAX_VALUE) {
            BooleanQuery.Builder bq = new BooleanQuery.Builder();
            bq.add(q, Occur.MUST);
            SchemaField sf = ulog.getVersionInfo().getVersionField();
            ValueSource vs = sf.getType().getValueSource(sf, null);
            ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, Long.toString(Math.abs(cmd.getVersion())), null, true, true);
            FunctionRangeQuery range = new FunctionRangeQuery(filt);
            // formulated in the "MUST_NOT" sense so we can delete docs w/o a version (some tests depend on this...)
            bq.add(range, Occur.MUST_NOT);
            q = bq.build();
        }
        return q;
    } catch (SyntaxError e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) FunctionRangeQuery(org.apache.solr.search.FunctionRangeQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FunctionRangeQuery(org.apache.solr.search.FunctionRangeQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ValueSourceRangeFilter(org.apache.solr.search.function.ValueSourceRangeFilter) SyntaxError(org.apache.solr.search.SyntaxError) ValueSource(org.apache.lucene.queries.function.ValueSource) QParser(org.apache.solr.search.QParser) SolrException(org.apache.solr.common.SolrException)

Example 2 with ValueSourceRangeFilter

use of org.apache.solr.search.function.ValueSourceRangeFilter in project lucene-solr by apache.

the class NumericFieldType method getRangeQueryForFloatDoubleDocValues.

protected Query getRangeQueryForFloatDoubleDocValues(SchemaField sf, String min, String max, boolean minInclusive, boolean maxInclusive) {
    Query query;
    String fieldName = sf.getName();
    Number minVal = min == null ? null : getNumberType() == NumberType.FLOAT ? Float.parseFloat(min) : Double.parseDouble(min);
    Number maxVal = max == null ? null : getNumberType() == NumberType.FLOAT ? Float.parseFloat(max) : Double.parseDouble(max);
    Long minBits = min == null ? null : getNumberType() == NumberType.FLOAT ? (long) Float.floatToIntBits(minVal.floatValue()) : Double.doubleToLongBits(minVal.doubleValue());
    Long maxBits = max == null ? null : getNumberType() == NumberType.FLOAT ? (long) Float.floatToIntBits(maxVal.floatValue()) : Double.doubleToLongBits(maxVal.doubleValue());
    long negativeInfinityBits = getNumberType() == NumberType.FLOAT ? FLOAT_NEGATIVE_INFINITY_BITS : DOUBLE_NEGATIVE_INFINITY_BITS;
    long positiveInfinityBits = getNumberType() == NumberType.FLOAT ? FLOAT_POSITIVE_INFINITY_BITS : DOUBLE_POSITIVE_INFINITY_BITS;
    long minusZeroBits = getNumberType() == NumberType.FLOAT ? FLOAT_MINUS_ZERO_BITS : DOUBLE_MINUS_ZERO_BITS;
    long zeroBits = getNumberType() == NumberType.FLOAT ? FLOAT_ZERO_BITS : DOUBLE_ZERO_BITS;
    // If min is negative (or -0d) and max is positive (or +0d), then issue a FunctionRangeQuery
    if ((minVal == null || minVal.doubleValue() < 0d || minBits == minusZeroBits) && (maxVal == null || (maxVal.doubleValue() > 0d || maxBits == zeroBits))) {
        ValueSource vs = getValueSource(sf, null);
        query = new FunctionRangeQuery(new ValueSourceRangeFilter(vs, min, max, minInclusive, maxInclusive));
    } else {
        // If both max and min are negative (or -0d), then issue range query with max and min reversed
        if ((minVal == null || minVal.doubleValue() < 0d || minBits == minusZeroBits) && (maxVal != null && (maxVal.doubleValue() < 0d || maxBits == minusZeroBits))) {
            query = numericDocValuesRangeQuery(fieldName, maxBits, (min == null ? Long.valueOf(negativeInfinityBits) : minBits), maxInclusive, minInclusive, false);
        } else {
            // If both max and min are positive, then issue range query
            query = numericDocValuesRangeQuery(fieldName, minBits, (max == null ? Long.valueOf(positiveInfinityBits) : maxBits), minInclusive, maxInclusive, false);
        }
    }
    return query;
}
Also used : FunctionRangeQuery(org.apache.solr.search.FunctionRangeQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) FunctionRangeQuery(org.apache.solr.search.FunctionRangeQuery) ValueSourceRangeFilter(org.apache.solr.search.function.ValueSourceRangeFilter) ValueSource(org.apache.lucene.queries.function.ValueSource)

Example 3 with ValueSourceRangeFilter

use of org.apache.solr.search.function.ValueSourceRangeFilter in project lucene-solr by apache.

the class CurrencyValue method getRangeQuery.

public Query getRangeQuery(QParser parser, SchemaField field, final CurrencyValue p1, final CurrencyValue p2, final boolean minInclusive, final boolean maxInclusive) {
    String currencyCode = (p1 != null) ? p1.getCurrencyCode() : (p2 != null) ? p2.getCurrencyCode() : defaultCurrency;
    // ValueSourceRangeFilter doesn't check exists(), so we have to
    final Filter docsWithValues = new QueryWrapperFilter(new FieldValueQuery(getAmountField(field).getName()));
    final Filter vsRangeFilter = new ValueSourceRangeFilter(new RawCurrencyValueSource(field, currencyCode, parser), p1 == null ? null : p1.getAmount() + "", p2 == null ? null : p2.getAmount() + "", minInclusive, maxInclusive);
    final BooleanQuery.Builder docsInRange = new BooleanQuery.Builder();
    docsInRange.add(docsWithValues, Occur.FILTER);
    docsInRange.add(vsRangeFilter, Occur.FILTER);
    return new SolrConstantScoreQuery(new QueryWrapperFilter(docsInRange.build()));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) ValueSourceRangeFilter(org.apache.solr.search.function.ValueSourceRangeFilter) ValueSourceRangeFilter(org.apache.solr.search.function.ValueSourceRangeFilter) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) Filter(org.apache.solr.search.Filter) FieldValueQuery(org.apache.lucene.search.FieldValueQuery) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) SolrConstantScoreQuery(org.apache.solr.search.SolrConstantScoreQuery)

Aggregations

ValueSourceRangeFilter (org.apache.solr.search.function.ValueSourceRangeFilter)3 ValueSource (org.apache.lucene.queries.function.ValueSource)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 Query (org.apache.lucene.search.Query)2 FunctionRangeQuery (org.apache.solr.search.FunctionRangeQuery)2 FieldValueQuery (org.apache.lucene.search.FieldValueQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 SolrException (org.apache.solr.common.SolrException)1 SchemaField (org.apache.solr.schema.SchemaField)1 Filter (org.apache.solr.search.Filter)1 QParser (org.apache.solr.search.QParser)1 QueryWrapperFilter (org.apache.solr.search.QueryWrapperFilter)1 SolrConstantScoreQuery (org.apache.solr.search.SolrConstantScoreQuery)1 SyntaxError (org.apache.solr.search.SyntaxError)1