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;
}
Aggregations