/** Construct the Weight for this Query searched by searcher. Recursively construct subquery weights. */ public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(DisjunctionMaxQuery.this); for (Query disjunctQuery : disjuncts) { weights.add(searcher.createWeight(disjunctQuery, needsScores, boost)); } this.needsScores = needsScores; }
@Override public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { final Weight innerWeight = searcher.createWeight(query, false, 1f); if (needsScores) { return new ConstantScoreWeight(this, boost) {
/** * Creates a normalized weight for a top-level {@link Query}. * The query is rewritten by this method and {@link Query#createWeight} called, * afterwards the {@link Weight} is normalized. The returned {@code Weight} * can then directly be used to get a {@link Scorer}. * @lucene.internal * * @deprecated Clients should rewrite the query and then call {@link #createWeight(Query, boolean, float)} * with a boost value of 1f */ @Deprecated public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException { query = rewrite(query); return createWeight(query, needsScores, 1f); }
/** Lower-level search API. * * <p>{@link LeafCollector#collect(int)} is called for every matching document. * * @throws BooleanQuery.TooManyClauses If a query would exceed * {@link BooleanQuery#getMaxClauseCount()} clauses. */ public void search(Query query, Collector results) throws IOException { query = rewrite(query); search(leafContexts, createWeight(query, results.needsScores(), 1), results); }
BooleanWeight(BooleanQuery query, IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(query); this.query = query; this.needsScores = needsScores; this.similarity = searcher.getSimilarity(needsScores); weights = new ArrayList<>(); for (BooleanClause c : query) { Weight w = searcher.createWeight(c.getQuery(), needsScores && c.isScoring(), boost); weights.add(w); } }
/** Returns an Explanation that describes how <code>doc</code> scored against * <code>query</code>. * * <p>This is intended to be used in developing Similarity implementations, * and, for good performance, should not be displayed with every hit. * Computing an explanation is as expensive as executing the query over the * entire index. */ public Explanation explain(Query query, int doc) throws IOException { query = rewrite(query); return explain(createWeight(query, true, 1), doc); }
private static Scorer getScorer(Query query, CodecReader reader) throws IOException { IndexSearcher s = new IndexSearcher(reader); s.setQueryCache(null); Weight weight = s.createWeight(s.rewrite(query), false, 1.0f); return weight.scorer(reader.getContext()); }
final Weight weight = createWeight(query, needsScores, 1); final List<Future<C>> topDocsFutures = new ArrayList<>(leafSlices.length); for (int i = 0; i < leafSlices.length; ++i) {
searcher.setQueryCache(null); query = searcher.rewrite(query); final Weight weight = searcher.createWeight(query, false, 1); final Scorer scorer = weight.scorer(readerContext); if (scorer != null) {
Weight weight = searcher.createWeight(rewritten, true, 1);
@Override public Weight createWeight(Query query, boolean needsScores, float boost) throws IOException { if (profiler != null) { // createWeight() is called for each query in the tree, so we tell the queryProfiler // each invocation so that it can build an internal representation of the query // tree QueryProfileBreakdown profile = profiler.getQueryBreakdown(query); Timer timer = profile.getTimer(QueryTimingType.CREATE_WEIGHT); timer.start(); final Weight weight; try { weight = super.createWeight(query, needsScores, boost); } finally { timer.stop(); profiler.pollLastElement(); } return new ProfileWeight(query, weight, profile); } else { // needs to be 'super', not 'in' in order to use aggregated DFS return super.createWeight(query, needsScores, boost); } }
searcher.setQueryCache(null); final Query query = LongPoint.newRangeQuery(SeqNoFieldMapper.NAME, fromSeqNo, toSeqNo); final Weight weight = searcher.createWeight(query, false, 1.0f); for (LeafReaderContext leaf : reader.leaves()) { final Scorer scorer = weight.scorer(leaf);
static CodecReader wrapReader(String recoverySourceField, CodecReader reader, Supplier<Query> retainSourceQuerySupplier) throws IOException { NumericDocValues recoverySource = reader.getNumericDocValues(recoverySourceField); if (recoverySource == null || recoverySource.nextDoc() == DocIdSetIterator.NO_MORE_DOCS) { return reader; // early terminate - nothing to do here since non of the docs has a recovery source anymore. } BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.add(new DocValuesFieldExistsQuery(recoverySourceField), BooleanClause.Occur.FILTER); builder.add(retainSourceQuerySupplier.get(), BooleanClause.Occur.FILTER); IndexSearcher s = new IndexSearcher(reader); s.setQueryCache(null); Weight weight = s.createWeight(s.rewrite(builder.build()), false, 1.0f); Scorer scorer = weight.scorer(reader.getContext()); if (scorer != null) { return new SourcePruningFilterCodecReader(recoverySourceField, reader, BitSet.of(scorer.iterator(), reader.maxDoc())); } else { return new SourcePruningFilterCodecReader(recoverySourceField, reader, null); } }
/** Construct the Weight for this Query searched by searcher. Recursively construct subquery weights. */ public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(DisjunctionMaxQuery.this); for (Query disjunctQuery : disjuncts) { weights.add(searcher.createWeight(disjunctQuery, needsScores, boost)); } this.needsScores = needsScores; }
@Override public void createWeight(Map context, IndexSearcher searcher) throws IOException { Query rewritten = searcher.rewrite(q); Weight w = searcher.createWeight(rewritten, true, 1); context.put(this, w); } }
/** Lower-level search API. * * <p>{@link LeafCollector#collect(int)} is called for every matching document. * * @throws BooleanQuery.TooManyClauses If a query would exceed * {@link BooleanQuery#getMaxClauseCount()} clauses. */ public void search(Query query, Collector results) throws IOException { query = rewrite(query); search(leafContexts, createWeight(query, results.needsScores(), 1), results); }
public BoostedWeight(IndexSearcher searcher, boolean needsScores) throws IOException { super(BoostedQuery.this); this.qWeight = searcher.createWeight(q, needsScores); this.fcontext = ValueSource.newContext(searcher); boostVal.createWeight(fcontext,searcher); }
public BoostedWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { super(BoostedQuery.this); this.qWeight = searcher.createWeight(q, needsScores, boost); this.fcontext = ValueSource.newContext(searcher); boostVal.createWeight(fcontext,searcher); }
public BoostedWeight(IndexSearcher searcher, boolean needsScores) throws IOException { super(BoostedQuery.this); this.qWeight = searcher.createWeight(q, needsScores); this.fcontext = ValueSource.newContext(searcher); boostVal.createWeight(fcontext,searcher); }
private static Scorer getScorer(Query query, CodecReader reader) throws IOException { IndexSearcher s = new IndexSearcher(reader); s.setQueryCache(null); Weight weight = s.createWeight(s.rewrite(query), false, 1.0f); return weight.scorer(reader.getContext()); }