@Override public void setBoost(final float b) { nodeQuery.setBoost(b); }
@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 protected void addClause(final NodeBooleanQuery topLevel, final Term term, final int docFreq, final float boost, final TermContext states) { final NodeQuery q = new NodeConstantScoreQuery(new NodeTermQuery(term, states)); q.setBoost(boost); topLevel.add(q, NodeBooleanClause.Occur.SHOULD); } }
query.setBoost(this.getBoost() * query.getBoost());
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { final com.sindicetech.siren.search.node.NodeQuery query = (com.sindicetech.siren.search.node.NodeQuery) parser.parse(booleanExpression, ""); if (this.hasLevel()) { query.setLevelConstraint(this.getLevel()); } if (this.hasRange()) { query.setNodeConstraint(this.getLowerBound(), this.getUpperBound()); } if (this.hasBoost()) { query.setBoost(this.getBoost()); } // should we wrap the query into a lucene proxy if (proxy) { return new LuceneProxyNodeQuery(query); } return query; }
@Override public Query rewrite(final IndexReader reader, final MultiNodeTermQuery query) throws IOException { // Disabled cutoffs final int docCountCutoff = Integer.MAX_VALUE; final int termCountLimit = Integer.MAX_VALUE; final CutOffTermCollector col = new CutOffTermCollector(docCountCutoff, termCountLimit); this.collectTerms(reader, query, col); final int size = col.pendingTerms.size(); if (col.hasCutOff) { return MultiNodeTermQuery.CONSTANT_SCORE_FILTER_REWRITE.rewrite(reader, query); } else if (size == 0) { return this.getTopLevelQuery(query); } else { final NodeBooleanQuery bq = this.getTopLevelQuery(query); final BytesRefHash pendingTerms = col.pendingTerms; final int sort[] = pendingTerms.sort(col.termsEnum.getComparator()); for(int i = 0; i < size; i++) { final int pos = sort[i]; // docFreq is not used for constant score here, we pass 1 // to explicitely set a fake value, so it's not calculated this.addClause(bq, new Term(query.field, pendingTerms.get(pos, new BytesRef())), 1, 1.0f, col.array.termState[pos]); } // Strip scores final NodeQuery result = new NodeConstantScoreQuery(bq); result.setBoost(query.getBoost()); return result; } }
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { // ensure that the attribute is unset ((ConciseKeywordQueryParser) parser).unsetAttribute(); // set attribute if (this.hasAttribute) { ((ConciseKeywordQueryParser) parser).setAttribute(attribute); } final com.sindicetech.siren.search.node.NodeQuery query = (com.sindicetech.siren.search.node.NodeQuery) parser.parse(booleanExpression, ""); if (this.hasLevel()) { query.setLevelConstraint(this.getLevel()); } if (this.hasRange()) { query.setNodeConstraint(this.getLowerBound(), this.getUpperBound()); } if (this.hasBoost()) { query.setBoost(this.getBoost()); } // should we wrap the query into a lucene proxy if (proxy) { return new LuceneProxyNodeQuery(query); } return query; }
@Test public void testBoostQuery() throws Exception { final BooleanQuery q = new BooleanQuery(); q.add(ntq("c").getLuceneProxyQuery(), BooleanClause.Occur.MUST); final NodeQuery nq = ntq("b").getQuery(); nq.setBoost(2); q.add(new LuceneProxyNodeQuery(nq), BooleanClause.Occur.MUST); this._assertSirenQuery(q, "c b^2"); }