@Override public NodeQuery rewrite(final IndexReader reader) throws IOException { if (query != null) { NodeQuery rewritten = (NodeQuery) query.rewrite(reader); if (rewritten != query) { rewritten = new NodeConstantScoreQuery(rewritten); rewritten.setBoost(this.getBoost()); return rewritten; } } return this; }
@Override public Explanation explain(final AtomicReaderContext context, final int doc) throws IOException { final NodeScorer cs = (NodeScorer) this.scorer(context, true, false, context.reader().getLiveDocs()); final boolean exists = (cs != null && cs.skipToCandidate(doc) && cs.doc() == doc && cs.nextNode()); final ComplexExplanation result = new ComplexExplanation(); if (exists) { result.setDescription(NodeConstantScoreQuery.this.toString() + ", product of:"); result.setValue(queryWeight); result.setMatch(Boolean.TRUE); result.addDetail(new Explanation(NodeConstantScoreQuery.this.getBoost(), "boost")); result.addDetail(new Explanation(queryNorm, "queryNorm")); } else { result.setDescription(NodeConstantScoreQuery.this.toString() + " doesn't match id " + doc); result.setValue(0); result.setMatch(Boolean.FALSE); } return result; } }
@Override public Query rewrite(final IndexReader reader, final MultiNodeTermQuery query) throws IOException { final NodeBooleanQuery bq = SCORING_BOOLEAN_QUERY_REWRITE.rewrite(reader, query); // TODO: if empty boolean query return NullQuery? if (bq.clauses().isEmpty()) { return bq; } // strip the scores off final Query result = new NodeConstantScoreQuery(bq); result.setBoost(query.getBoost()); return result; }
@Override public float getValueForNormalization() throws IOException { // we calculate sumOfSquaredWeights of the inner weight, but ignore it (just to initialize everything) if (innerWeight != null) innerWeight.getValueForNormalization(); queryWeight = NodeConstantScoreQuery.this.getBoost(); return queryWeight * queryWeight; }
@Override protected void addClause(final NodeBooleanQuery topLevel, final Term term, final int docFreq, final float boost, final TermContext states) { final NodePrimitiveQuery q = new NodeConstantScoreQuery(new NodeTermQuery(term, states)); q.setBoost(boost); topLevel.add(q, NodeBooleanClause.Occur.SHOULD); } }
@Override public String toString(final String field) { return new StringBuilder("NodeConstantScore(") .append((query == null) ? filter.toString() : query.toString(field)) .append(')') .append(ToStringUtils.boost(this.getBoost())) .toString(); }
final NodeQuery result = new NodeConstantScoreQuery(bq); result.setBoost(query.getBoost());