Search in sources :

Example 1 with DocsAndCost

use of org.apache.lucene.facet.DrillSidewaysScorer.DocsAndCost in project lucene-solr by apache.

the class DrillSidewaysQuery method createWeight.

@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
    final Weight baseWeight = baseQuery.createWeight(searcher, needsScores, boost);
    final Weight[] drillDowns = new Weight[drillDownQueries.length];
    for (int dim = 0; dim < drillDownQueries.length; dim++) {
        drillDowns[dim] = searcher.createNormalizedWeight(drillDownQueries[dim], false);
    }
    return new Weight(DrillSidewaysQuery.this) {

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

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

        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            // We can only run as a top scorer:
            throw new UnsupportedOperationException();
        }

        @Override
        public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
            Scorer baseScorer = baseWeight.scorer(context);
            DrillSidewaysScorer.DocsAndCost[] dims = new DrillSidewaysScorer.DocsAndCost[drillDowns.length];
            int nullCount = 0;
            for (int dim = 0; dim < dims.length; dim++) {
                Scorer scorer = drillDowns[dim].scorer(context);
                if (scorer == null) {
                    nullCount++;
                    scorer = new ConstantScoreScorer(drillDowns[dim], 0f, DocIdSetIterator.empty());
                }
                dims[dim] = new DrillSidewaysScorer.DocsAndCost(scorer, drillSidewaysCollectors[dim]);
            }
            //if (nullCount > 1 || (nullCount == 1 && dims.length == 1)) {
            if (nullCount > 1) {
                return null;
            }
            // Sort drill-downs by most restrictive first:
            Arrays.sort(dims, new Comparator<DrillSidewaysScorer.DocsAndCost>() {

                @Override
                public int compare(DocsAndCost o1, DocsAndCost o2) {
                    return Long.compare(o1.approximation.cost(), o2.approximation.cost());
                }
            });
            if (baseScorer == null) {
                return null;
            }
            return new DrillSidewaysScorer(context, baseScorer, drillDownCollector, dims, scoreSubDocsAtOnce);
        }
    };
}
Also used : Set(java.util.Set) DocsAndCost(org.apache.lucene.facet.DrillSidewaysScorer.DocsAndCost) DocsAndCost(org.apache.lucene.facet.DrillSidewaysScorer.DocsAndCost) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) Scorer(org.apache.lucene.search.Scorer) BulkScorer(org.apache.lucene.search.BulkScorer) Weight(org.apache.lucene.search.Weight) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Aggregations

Set (java.util.Set)1 DocsAndCost (org.apache.lucene.facet.DrillSidewaysScorer.DocsAndCost)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 BulkScorer (org.apache.lucene.search.BulkScorer)1 ConstantScoreScorer (org.apache.lucene.search.ConstantScoreScorer)1 Scorer (org.apache.lucene.search.Scorer)1 Weight (org.apache.lucene.search.Weight)1