@Override public Scorer scorer( AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException { if (stats == null) { return null; } else { return new SpanScorer( query.getSpans(context, acceptDocs, termContexts), this, similarity.sloppySimScorer(stats, context)); } }
public SpanWeight(SpanQuery query, IndexSearcher searcher) throws IOException { this.similarity = searcher.getSimilarity(); this.query = query; termContexts = new HashMap<Term, TermContext>(); TreeSet<Term> terms = new TreeSet<Term>(); query.extractTerms(terms); final IndexReaderContext context = searcher.getTopReaderContext(); final TermStatistics termStats[] = new TermStatistics[terms.size()]; int i = 0; for (Term term : terms) { TermContext state = TermContext.build(context, term, true); termStats[i] = searcher.termStatistics(term, state); termContexts.put(term, state); i++; } final String field = query.getField(); if (field != null) { stats = similarity.computeWeight( query.getBoost(), searcher.collectionStatistics(query.getField()), termStats); } }