Search in sources :

Example 6 with FieldValueQuery

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

the class TestJoinUtil method numericDocValuesScoreQuery.

// FunctionQuery would be helpful, but join module doesn't depend on queries module.
static Query numericDocValuesScoreQuery(final String field) {
    return new Query() {

        private final Query fieldQuery = new FieldValueQuery(field);

        @Override
        public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
            Weight fieldWeight = fieldQuery.createWeight(searcher, false, boost);
            return new Weight(this) {

                @Override
                public void extractTerms(Set<Term> terms) {
                }

                @Override
                public Explanation explain(LeafReaderContext context, int doc) throws IOException {
                    return null;
                }

                @Override
                public Scorer scorer(LeafReaderContext context) throws IOException {
                    Scorer fieldScorer = fieldWeight.scorer(context);
                    if (fieldScorer == null) {
                        return null;
                    }
                    NumericDocValues price = context.reader().getNumericDocValues(field);
                    return new FilterScorer(fieldScorer, this) {

                        @Override
                        public float score() throws IOException {
                            assertEquals(in.docID(), price.advance(in.docID()));
                            return (float) price.longValue();
                        }
                    };
                }
            };
        }

        @Override
        public String toString(String field) {
            return fieldQuery.toString(field);
        }

        @Override
        public boolean equals(Object o) {
            return o == this;
        }

        @Override
        public int hashCode() {
            return System.identityHashCode(this);
        }
    };
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValues(org.apache.lucene.index.NumericDocValues) SortedSet(java.util.SortedSet) BitSet(org.apache.lucene.util.BitSet) EnumSet(java.util.EnumSet) Set(java.util.Set) FixedBitSet(org.apache.lucene.util.FixedBitSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) FieldValueQuery(org.apache.lucene.search.FieldValueQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) FieldValueQuery(org.apache.lucene.search.FieldValueQuery) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Scorer(org.apache.lucene.search.Scorer) FilterScorer(org.apache.lucene.search.FilterScorer) FilterScorer(org.apache.lucene.search.FilterScorer) Weight(org.apache.lucene.search.Weight)

Example 7 with FieldValueQuery

use of org.apache.lucene.search.FieldValueQuery in project elasticsearch by elastic.

the class MaxAggregatorTests method testSomeMatchesNumericDocValues.

public void testSomeMatchesNumericDocValues() throws IOException {
    testCase(new FieldValueQuery("number"), iw -> {
        iw.addDocument(singleton(new NumericDocValuesField("number", 7)));
        iw.addDocument(singleton(new NumericDocValuesField("number", 1)));
    }, max -> {
        assertEquals(7, max.getValue(), 0);
    });
}
Also used : NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) FieldValueQuery(org.apache.lucene.search.FieldValueQuery)

Example 8 with FieldValueQuery

use of org.apache.lucene.search.FieldValueQuery in project elasticsearch by elastic.

the class ValueCountAggregatorTests method testSomeMatchesNumericDocValues.

public void testSomeMatchesNumericDocValues() throws IOException {
    testCase(new FieldValueQuery(FIELD_NAME), ValueType.NUMBER, iw -> {
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 7)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
    }, count -> assertEquals(2L, count.getValue()));
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) FieldValueQuery(org.apache.lucene.search.FieldValueQuery)

Example 9 with FieldValueQuery

use of org.apache.lucene.search.FieldValueQuery 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

FieldValueQuery (org.apache.lucene.search.FieldValueQuery)9 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)7 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 FilterScorer (org.apache.lucene.search.FilterScorer)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 Query (org.apache.lucene.search.Query)1 Scorer (org.apache.lucene.search.Scorer)1 TermQuery (org.apache.lucene.search.TermQuery)1 Weight (org.apache.lucene.search.Weight)1 BitSet (org.apache.lucene.util.BitSet)1