/** * Create a TopTermsSpanBooleanQueryRewrite for * at most <code>size</code> terms. */ public TopTermsSpanBooleanQueryRewrite(int size) { delegate = new TopTermsRewrite<SpanOrQuery>(size) { @Override protected int getMaxSize() { return Integer.MAX_VALUE; } @Override protected SpanOrQuery getTopLevelQuery() { return new SpanOrQuery(); } @Override protected void addClause(SpanOrQuery topLevel, Term term, int docFreq, float boost, TermContext states) { final SpanTermQuery q = new SpanTermQuery(term); q.setBoost(boost); topLevel.addClause(q); } }; }
/** * Create a new SpanMultiTermQueryWrapper. * * @param query Query to wrap. * <p> * NOTE: This will call {@link MultiTermQuery#setRewriteMethod(MultiTermQuery.RewriteMethod)} * on the wrapped <code>query</code>, changing its rewrite method to a suitable one for spans. * Be sure to not change the rewrite method on the wrapped query afterwards! Doing so will * throw {@link UnsupportedOperationException} on rewriting this query! */ @SuppressWarnings({"rawtypes","unchecked"}) public SpanMultiTermQueryWrapper(Q query) { this.query = query; MultiTermQuery.RewriteMethod method = query.getRewriteMethod(); if (method instanceof TopTermsRewrite) { final int pqsize = ((TopTermsRewrite) method).getSize(); setRewriteMethod(new TopTermsSpanBooleanQueryRewrite(pqsize)); } else { setRewriteMethod(SCORING_SPAN_QUERY_REWRITE); } }