Search in sources :

Example 1 with QueryWrapperFilter

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

the class ExpandComponent method getGroupQuery.

private Query getGroupQuery(String fname, FieldType ft, int size, LongHashSet groupSet) {
    BytesRef[] bytesRefs = new BytesRef[size];
    BytesRefBuilder term = new BytesRefBuilder();
    Iterator<LongCursor> it = groupSet.iterator();
    int index = -1;
    while (it.hasNext()) {
        LongCursor cursor = it.next();
        String stringVal = numericToString(ft, cursor.value);
        ft.readableToIndexed(stringVal, term);
        bytesRefs[++index] = term.toBytesRef();
    }
    return new SolrConstantScoreQuery(new QueryWrapperFilter(new TermInSetQuery(fname, bytesRefs)));
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) LongCursor(com.carrotsearch.hppc.cursors.LongCursor) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) SolrConstantScoreQuery(org.apache.solr.search.SolrConstantScoreQuery) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with QueryWrapperFilter

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

the class ChildDocTransformer method create.

@Override
public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {
    SchemaField uniqueKeyField = req.getSchema().getUniqueKeyField();
    if (uniqueKeyField == null) {
        throw new SolrException(ErrorCode.BAD_REQUEST, " ChildDocTransformer requires the schema to have a uniqueKeyField.");
    }
    String parentFilter = params.get("parentFilter");
    if (parentFilter == null) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Parent filter should be sent as parentFilter=filterCondition");
    }
    String childFilter = params.get("childFilter");
    int limit = params.getInt("limit", 10);
    BitSetProducer parentsFilter = null;
    try {
        Query parentFilterQuery = QParser.getParser(parentFilter, req).getQuery();
        parentsFilter = new QueryBitSetProducer(new QueryWrapperFilter(parentFilterQuery));
    } catch (SyntaxError syntaxError) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Failed to create correct parent filter query");
    }
    Query childFilterQuery = null;
    if (childFilter != null) {
        try {
            childFilterQuery = QParser.getParser(childFilter, req).getQuery();
        } catch (SyntaxError syntaxError) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Failed to create correct child filter query");
        }
    }
    return new ChildDocTransformer(field, parentsFilter, uniqueKeyField, req.getSchema(), childFilterQuery, limit);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) Query(org.apache.lucene.search.Query) ToChildBlockJoinQuery(org.apache.lucene.search.join.ToChildBlockJoinQuery) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) BitSetProducer(org.apache.lucene.search.join.BitSetProducer) SyntaxError(org.apache.solr.search.SyntaxError) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) SolrException(org.apache.solr.common.SolrException)

Example 3 with QueryWrapperFilter

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

the class ExpandComponent method getGroupQuery.

private Query getGroupQuery(String fname, int size, IntObjectHashMap<BytesRef> ordBytes) throws Exception {
    BytesRef[] bytesRefs = new BytesRef[size];
    int index = -1;
    Iterator<IntObjectCursor<BytesRef>> it = ordBytes.iterator();
    while (it.hasNext()) {
        IntObjectCursor<BytesRef> cursor = it.next();
        bytesRefs[++index] = cursor.value;
    }
    return new SolrConstantScoreQuery(new QueryWrapperFilter(new TermInSetQuery(fname, bytesRefs)));
}
Also used : IntObjectCursor(com.carrotsearch.hppc.cursors.IntObjectCursor) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) SolrConstantScoreQuery(org.apache.solr.search.SolrConstantScoreQuery) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) BytesRef(org.apache.lucene.util.BytesRef)

Example 4 with QueryWrapperFilter

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

the class ExpandComponent method getPointGroupQuery.

private Query getPointGroupQuery(SchemaField sf, int size, LongHashSet groupSet) {
    Iterator<LongCursor> it = groupSet.iterator();
    List<String> values = new ArrayList<>(size);
    FieldType ft = sf.getType();
    while (it.hasNext()) {
        LongCursor cursor = it.next();
        values.add(numericToString(ft, cursor.value));
    }
    return new SolrConstantScoreQuery(new QueryWrapperFilter(sf.getType().getSetQuery(null, sf, values)));
}
Also used : LongCursor(com.carrotsearch.hppc.cursors.LongCursor) ArrayList(java.util.ArrayList) SolrConstantScoreQuery(org.apache.solr.search.SolrConstantScoreQuery) QueryWrapperFilter(org.apache.solr.search.QueryWrapperFilter) FieldType(org.apache.solr.schema.FieldType)

Example 5 with QueryWrapperFilter

use of org.apache.solr.search.QueryWrapperFilter 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

QueryWrapperFilter (org.apache.solr.search.QueryWrapperFilter)5 SolrConstantScoreQuery (org.apache.solr.search.SolrConstantScoreQuery)4 LongCursor (com.carrotsearch.hppc.cursors.LongCursor)2 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)2 BytesRef (org.apache.lucene.util.BytesRef)2 IntObjectCursor (com.carrotsearch.hppc.cursors.IntObjectCursor)1 ArrayList (java.util.ArrayList)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 FieldValueQuery (org.apache.lucene.search.FieldValueQuery)1 Query (org.apache.lucene.search.Query)1 BitSetProducer (org.apache.lucene.search.join.BitSetProducer)1 QueryBitSetProducer (org.apache.lucene.search.join.QueryBitSetProducer)1 ToChildBlockJoinQuery (org.apache.lucene.search.join.ToChildBlockJoinQuery)1 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)1 SolrException (org.apache.solr.common.SolrException)1 FieldType (org.apache.solr.schema.FieldType)1 SchemaField (org.apache.solr.schema.SchemaField)1 Filter (org.apache.solr.search.Filter)1 SyntaxError (org.apache.solr.search.SyntaxError)1 ValueSourceRangeFilter (org.apache.solr.search.function.ValueSourceRangeFilter)1