Search in sources :

Example 1 with Scorable

use of org.apache.lucene.search.Scorable in project OpenGrok by OpenGrok.

the class SuggesterSearcher method getComplexQueryData.

private ComplexQueryData getComplexQueryData(final Query query, final LeafReaderContext leafReaderContext) {
    ComplexQueryData data = new ComplexQueryData();
    if (query == null || query instanceof SuggesterQuery) {
        data.documentIds = new BitIntsHolder(0);
        return data;
    }
    BitIntsHolder documentIds = new BitIntsHolder();
    try {
        search(query, new Collector() {

            @Override
            public LeafCollector getLeafCollector(final LeafReaderContext context) {
                return new LeafCollector() {

                    final int docBase = context.docBase;

                    @Override
                    public void setScorer(final Scorable scorer) {
                        if (leafReaderContext == context) {
                            if (scorer instanceof PhraseScorer) {
                                data.scorer = (PhraseScorer) scorer;
                            } else {
                                try {
                                    // in #setScorer but no better way was found
                                    for (Scorer.ChildScorable childScorer : scorer.getChildren()) {
                                        if (childScorer.child instanceof PhraseScorer) {
                                            data.scorer = (PhraseScorer) childScorer.child;
                                        }
                                    }
                                } catch (Exception e) {
                                // ignore
                                }
                            }
                        }
                    }

                    @Override
                    public void collect(int doc) {
                        if (leafReaderContext == context) {
                            documentIds.set(docBase + doc);
                        }
                    }
                };
            }

            @Override
            public ScoreMode scoreMode() {
                return ScoreMode.COMPLETE_NO_SCORES;
            }
        });
    } catch (IOException e) {
        if (Thread.currentThread().isInterrupted()) {
            interrupted = true;
            return null;
        } else {
            logger.log(Level.WARNING, "Could not get document ids for " + query, e);
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Could not get document ids for " + query, e);
    }
    data.documentIds = documentIds;
    return data;
}
Also used : ScoreMode(org.apache.lucene.search.ScoreMode) BitIntsHolder(org.opengrok.suggest.query.data.BitIntsHolder) Scorable(org.apache.lucene.search.Scorable) SuggesterQuery(org.opengrok.suggest.query.SuggesterQuery) IOException(java.io.IOException) PhraseScorer(org.opengrok.suggest.query.PhraseScorer) IOException(java.io.IOException) LeafCollector(org.apache.lucene.search.LeafCollector) LeafCollector(org.apache.lucene.search.LeafCollector) Collector(org.apache.lucene.search.Collector) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Aggregations

IOException (java.io.IOException)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Collector (org.apache.lucene.search.Collector)1 LeafCollector (org.apache.lucene.search.LeafCollector)1 Scorable (org.apache.lucene.search.Scorable)1 ScoreMode (org.apache.lucene.search.ScoreMode)1 PhraseScorer (org.opengrok.suggest.query.PhraseScorer)1 SuggesterQuery (org.opengrok.suggest.query.SuggesterQuery)1 BitIntsHolder (org.opengrok.suggest.query.data.BitIntsHolder)1