Search in sources :

Example 1 with FilterScorer

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

Aggregations

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 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 FieldValueQuery (org.apache.lucene.search.FieldValueQuery)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 FixedBitSet (org.apache.lucene.util.FixedBitSet)1