You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/09/07 15:34:48 UTC
svn commit: r1701621 [4/6] - in /lucene/dev/trunk: lucene/
lucene/core/src/java/org/apache/lucene/search/
lucene/core/src/java/org/apache/lucene/search/payloads/
lucene/core/src/java/org/apache/lucene/search/similarities/
lucene/core/src/java/org/apach...
Modified: lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java Mon Sep 7 13:34:46 2015
@@ -30,7 +30,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LongValues;
@@ -111,9 +110,6 @@ final class GlobalOrdinalsWithScoreQuery
private final Weight approximationWeight;
- private float queryNorm;
- private float queryWeight;
-
W(Query query, Weight approximationWeight) {
super(query);
this.approximationWeight = approximationWeight;
@@ -144,14 +140,13 @@ final class GlobalOrdinalsWithScoreQuery
@Override
public float getValueForNormalization() throws IOException {
- queryWeight = getBoost();
- return queryWeight * queryWeight;
+ return 1f;
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- this.queryNorm = norm * topLevelBoost;
- queryWeight *= this.queryNorm;
+ public void normalize(float norm, float boost) {
+ // no normalization, we ignore the normalization process
+ // and produce scores based on the join
}
@Override
Modified: lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java Mon Sep 7 13:34:46 2015
@@ -34,7 +34,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BitSetIterator;
-import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefHash;
import org.apache.lucene.util.FixedBitSet;
@@ -78,12 +77,10 @@ class TermsIncludingScoreQuery extends Q
public Query rewrite(IndexReader reader) throws IOException {
final Query originalQueryRewrite = originalQuery.rewrite(reader);
if (originalQueryRewrite != originalQuery) {
- Query rewritten = new TermsIncludingScoreQuery(field, multipleValuesPerDocument, terms, scores,
+ return new TermsIncludingScoreQuery(field, multipleValuesPerDocument, terms, scores,
ords, originalQueryRewrite, originalQuery);
- rewritten.setBoost(getBoost());
- return rewritten;
} else {
- return this;
+ return super.rewrite(reader);
}
}
@@ -146,12 +143,12 @@ class TermsIncludingScoreQuery extends Q
@Override
public float getValueForNormalization() throws IOException {
- return originalWeight.getValueForNormalization() * TermsIncludingScoreQuery.this.getBoost() * TermsIncludingScoreQuery.this.getBoost();
+ return originalWeight.getValueForNormalization();
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- originalWeight.normalize(norm, topLevelBoost * TermsIncludingScoreQuery.this.getBoost());
+ public void normalize(float norm, float boost) {
+ originalWeight.normalize(norm, boost);
}
@Override
Modified: lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java (original)
+++ lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java Mon Sep 7 13:34:46 2015
@@ -91,14 +91,12 @@ public class ToChildBlockJoinQuery exten
}
private static class ToChildBlockJoinWeight extends Weight {
- private final Query joinQuery;
private final Weight parentWeight;
private final BitSetProducer parentsFilter;
private final boolean doScores;
public ToChildBlockJoinWeight(Query joinQuery, Weight parentWeight, BitSetProducer parentsFilter, boolean doScores) {
super(joinQuery);
- this.joinQuery = joinQuery;
this.parentWeight = parentWeight;
this.parentsFilter = parentsFilter;
this.doScores = doScores;
@@ -109,12 +107,12 @@ public class ToChildBlockJoinQuery exten
@Override
public float getValueForNormalization() throws IOException {
- return parentWeight.getValueForNormalization() * joinQuery.getBoost() * joinQuery.getBoost();
+ return parentWeight.getValueForNormalization();
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- parentWeight.normalize(norm, topLevelBoost * joinQuery.getBoost());
+ public void normalize(float norm, float boost) {
+ parentWeight.normalize(norm, boost);
}
// NOTE: acceptDocs applies (and is checked) only in the
@@ -317,13 +315,11 @@ public class ToChildBlockJoinQuery exten
public Query rewrite(IndexReader reader) throws IOException {
final Query parentRewrite = parentQuery.rewrite(reader);
if (parentRewrite != parentQuery) {
- Query rewritten = new ToChildBlockJoinQuery(parentQuery,
+ return new ToChildBlockJoinQuery(parentQuery,
parentRewrite,
parentsFilter);
- rewritten.setBoost(getBoost());
- return rewritten;
} else {
- return this;
+ return super.rewrite(reader);
}
}
@@ -352,10 +348,4 @@ public class ToChildBlockJoinQuery exten
hash = prime * hash + parentsFilter.hashCode();
return hash;
}
-
- @Override
- public ToChildBlockJoinQuery clone() {
- return new ToChildBlockJoinQuery(origParentQuery.clone(),
- parentsFilter);
- }
}
Modified: lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java (original)
+++ lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java Mon Sep 7 13:34:46 2015
@@ -144,12 +144,12 @@ public class ToParentBlockJoinQuery exte
@Override
public float getValueForNormalization() throws IOException {
- return childWeight.getValueForNormalization() * joinQuery.getBoost() * joinQuery.getBoost();
+ return childWeight.getValueForNormalization();
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- childWeight.normalize(norm, topLevelBoost * joinQuery.getBoost());
+ public void normalize(float norm, float boost) {
+ childWeight.normalize(norm, boost);
}
// NOTE: acceptDocs applies (and is checked) only in the
@@ -413,14 +413,12 @@ public class ToParentBlockJoinQuery exte
public Query rewrite(IndexReader reader) throws IOException {
final Query childRewrite = childQuery.rewrite(reader);
if (childRewrite != childQuery) {
- Query rewritten = new ToParentBlockJoinQuery(origChildQuery,
+ return new ToParentBlockJoinQuery(origChildQuery,
childRewrite,
parentsFilter,
scoreMode);
- rewritten.setBoost(getBoost());
- return rewritten;
} else {
- return this;
+ return super.rewrite(reader);
}
}
Modified: lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java (original)
+++ lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java Mon Sep 7 13:34:46 2015
@@ -49,6 +49,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.FieldDoc;
@@ -441,8 +442,7 @@ public class TestBlockJoin extends Lucen
BooleanQuery.Builder bqB = new BooleanQuery.Builder();
bqB.add(q, BooleanClause.Occur.MUST);
BooleanQuery bq = bqB.build();
- bq.setBoost(2f);
- s.search(bq, 10);
+ s.search(new BoostQuery(bq, 2f), 10);
r.close();
dir.close();
}
Modified: lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java (original)
+++ lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java Mon Sep 7 13:34:46 2015
@@ -76,8 +76,8 @@ public abstract class SorterTestBase ext
}
@Override
- public SimWeight computeWeight(float queryBoost, CollectionStatistics collectionStats, TermStatistics... termStats) {
- return in.computeWeight(queryBoost, collectionStats, termStats);
+ public SimWeight computeWeight(CollectionStatistics collectionStats, TermStatistics... termStats) {
+ return in.computeWeight(collectionStats, termStats);
}
@Override
Modified: lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java (original)
+++ lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java Mon Sep 7 13:34:46 2015
@@ -423,9 +423,9 @@ public class TestDiversifiedTopDocsColle
}
@Override
- public SimWeight computeWeight(float queryBoost,
+ public SimWeight computeWeight(
CollectionStatistics collectionStats, TermStatistics... termStats) {
- return sim.computeWeight(queryBoost, collectionStats, termStats);
+ return sim.computeWeight(collectionStats, termStats);
}
@Override
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java Mon Sep 7 13:34:46 2015
@@ -49,9 +49,8 @@ public class BoostingQuery extends Query
public BoostingQuery(Query match, Query context, float boost) {
this.match = match;
- this.context = context.clone(); // clone before boost
+ this.context = context; // ignore context-only matches
this.boost = boost;
- this.context.setBoost(0.0f); // ignore context-only matches
}
@Override
@@ -59,9 +58,7 @@ public class BoostingQuery extends Query
Query matchRewritten = match.rewrite(reader);
Query contextRewritten = context.rewrite(reader);
if (match != matchRewritten || context != contextRewritten) {
- BoostingQuery rewritten = new BoostingQuery(matchRewritten, contextRewritten, boost);
- rewritten.setBoost(getBoost());
- return rewritten;
+ return new BoostingQuery(matchRewritten, contextRewritten, boost);
}
return super.rewrite(reader);
}
@@ -101,8 +98,8 @@ public class BoostingQuery extends Query
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- matchWeight.normalize(norm, topLevelBoost);
+ public void normalize(float norm, float boost) {
+ matchWeight.normalize(norm, boost);
}
@Override
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java Mon Sep 7 13:34:46 2015
@@ -29,11 +29,11 @@ import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.util.ToStringUtils;
/**
* A query that executes high-frequency terms in a optional sub-query to prevent
@@ -148,9 +148,7 @@ public class CommonTermsQuery extends Qu
if (this.terms.isEmpty()) {
return new MatchNoDocsQuery();
} else if (this.terms.size() == 1) {
- final Query tq = newTermQuery(this.terms.get(0), null);
- tq.setBoost(getBoost());
- return tq;
+ return newTermQuery(this.terms.get(0), null);
}
final List<LeafReaderContext> leaves = reader.leaves();
final int maxDoc = reader.maxDoc();
@@ -226,8 +224,7 @@ public class CommonTermsQuery extends Qu
}
lowFreq.setMinimumNumberShouldMatch(lowFreqMinShouldMatch);
Query lowFreqQuery = lowFreq.build();
- lowFreqQuery.setBoost(lowFreqBoost);
- builder.add(lowFreqQuery, Occur.MUST);
+ builder.add(new BoostQuery(lowFreqQuery, lowFreqBoost), Occur.MUST);
}
if (highFreqQueries.isEmpty() == false) {
BooleanQuery.Builder highFreq = new BooleanQuery.Builder();
@@ -237,12 +234,9 @@ public class CommonTermsQuery extends Qu
}
highFreq.setMinimumNumberShouldMatch(highFreqMinShouldMatch);
Query highFreqQuery = highFreq.build();
- highFreqQuery.setBoost(highFreqBoost);
- builder.add(highFreqQuery, Occur.SHOULD);
+ builder.add(new BoostQuery(highFreqQuery, highFreqBoost), Occur.SHOULD);
}
- Query rewritten = builder.build();
- rewritten.setBoost(getBoost());
- return rewritten;
+ return builder.build();
}
public void collectTermContext(IndexReader reader,
@@ -347,8 +341,7 @@ public class CommonTermsQuery extends Qu
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
- boolean needParens = (getBoost() != 1.0)
- || (getLowFreqMinimumNumberShouldMatch() > 0);
+ boolean needParens = (getLowFreqMinimumNumberShouldMatch() > 0);
if (needParens) {
buffer.append("(");
}
@@ -368,9 +361,6 @@ public class CommonTermsQuery extends Qu
buffer.append(getHighFreqMinimumNumberShouldMatch());
buffer.append(")");
}
- if (getBoost() != 1.0f) {
- buffer.append(ToStringUtils.boost(getBoost()));
- }
return buffer.toString();
}
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java Mon Sep 7 13:34:46 2015
@@ -34,8 +34,6 @@ import org.apache.lucene.search.IndexSea
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.ToStringUtils;
/**
* Query that sets document score as a programmatic function of several (sub) scores:
@@ -47,7 +45,7 @@ import org.apache.lucene.util.ToStringUt
*
* @lucene.experimental
*/
-public class CustomScoreQuery extends Query {
+public class CustomScoreQuery extends Query implements Cloneable {
private Query subQuery;
private Query[] scoringQueries; // never null (empty array if there are no valSrcQueries).
@@ -110,11 +108,17 @@ public class CustomScoreQuery extends Qu
/*(non-Javadoc) @see org.apache.lucene.search.Query#clone() */
@Override
public CustomScoreQuery clone() {
- CustomScoreQuery clone = (CustomScoreQuery)super.clone();
- clone.subQuery = subQuery.clone();
+ CustomScoreQuery clone;
+ try {
+ clone = (CustomScoreQuery)super.clone();
+ } catch (CloneNotSupportedException bogus) {
+ // cannot happen
+ throw new Error(bogus);
+ }
+ clone.subQuery = subQuery;
clone.scoringQueries = new Query[scoringQueries.length];
for(int i = 0; i < scoringQueries.length; i++) {
- clone.scoringQueries[i] = scoringQueries[i].clone();
+ clone.scoringQueries[i] = scoringQueries[i];
}
return clone;
}
@@ -129,7 +133,7 @@ public class CustomScoreQuery extends Qu
}
sb.append(")");
sb.append(strict?" STRICT" : "");
- return sb.toString() + ToStringUtils.boost(getBoost());
+ return sb.toString();
}
/** Returns true if <code>o</code> is equal to this. */
@@ -139,12 +143,8 @@ public class CustomScoreQuery extends Qu
return true;
if (!super.equals(o))
return false;
- if (getClass() != o.getClass()) {
- return false;
- }
CustomScoreQuery other = (CustomScoreQuery)o;
- if (this.getBoost() != other.getBoost() ||
- !this.subQuery.equals(other.subQuery) ||
+ if (!this.subQuery.equals(other.subQuery) ||
this.strict != other.strict ||
this.scoringQueries.length != other.scoringQueries.length) {
return false;
@@ -156,7 +156,7 @@ public class CustomScoreQuery extends Qu
@Override
public int hashCode() {
return (getClass().hashCode() + subQuery.hashCode() + Arrays.hashCode(scoringQueries))
- ^ Float.floatToIntBits(getBoost()) ^ (strict ? 1234 : 4321);
+ ^ (strict ? 1234 : 4321);
}
/**
@@ -199,9 +199,7 @@ public class CustomScoreQuery extends Qu
public float getValueForNormalization() throws IOException {
float sum = subQueryWeight.getValueForNormalization();
for (Weight valSrcWeight : valSrcWeights) {
- if (qStrict) {
- valSrcWeight.getValueForNormalization(); // do not include ValueSource part in the query normalization
- } else {
+ if (qStrict == false) { // otherwise do not include ValueSource part in the query normalization
sum += valSrcWeight.getValueForNormalization();
}
}
@@ -210,8 +208,8 @@ public class CustomScoreQuery extends Qu
/*(non-Javadoc) @see org.apache.lucene.search.Weight#normalize(float) */
@Override
- public void normalize(float norm, float topLevelBoost) {
- // note we DONT incorporate our boost, nor pass down any topLevelBoost
+ public void normalize(float norm, float boost) {
+ // note we DONT incorporate our boost, nor pass down any boost
// (e.g. from outer BQ), as there is no guarantee that the CustomScoreProvider's
// function obeys the distributive law... it might call sqrt() on the subQuery score
// or some other arbitrary function other than multiplication.
@@ -224,7 +222,7 @@ public class CustomScoreQuery extends Qu
valSrcWeight.normalize(norm, 1f);
}
}
- queryWeight = topLevelBoost * getBoost();
+ queryWeight = boost;
}
@Override
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java Mon Sep 7 13:34:46 2015
@@ -56,7 +56,6 @@ import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.DocIdSetBuilder;
import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.ToStringUtils;
/**
* Specialization for a disjunction over many terms that behaves like a
@@ -149,9 +148,7 @@ public class TermsQuery extends Query im
for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
bq.add(new TermQuery(new Term(iterator.field(), BytesRef.deepCopyOf(term))), Occur.SHOULD);
}
- ConstantScoreQuery csq = new ConstantScoreQuery(bq.build());
- csq.setBoost(getBoost());
- return csq;
+ return new ConstantScoreQuery(bq.build());
}
return super.rewrite(reader);
}
@@ -188,7 +185,6 @@ public class TermsQuery extends Query im
builder.append(iterator.field()).append(':');
builder.append(term.utf8ToString());
}
- builder.append(ToStringUtils.boost(getBoost()));
return builder.toString();
}
@@ -309,8 +305,9 @@ public class TermsQuery extends Query im
bq.add(new TermQuery(new Term(t.field, t.term), termContext), Occur.SHOULD);
}
Query q = new ConstantScoreQuery(bq.build());
- q.setBoost(score());
- return new WeightOrDocIdSet(searcher.rewrite(q).createWeight(searcher, needsScores));
+ final Weight weight = searcher.rewrite(q).createWeight(searcher, needsScores);
+ weight.normalize(1f, score());
+ return new WeightOrDocIdSet(weight);
} else {
assert builder != null;
return new WeightOrDocIdSet(builder.build());
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java Mon Sep 7 13:34:46 2015
@@ -39,8 +39,8 @@ import org.apache.lucene.util.ToStringUt
*/
// TODO: BoostedQuery and BoostingQuery in the same module?
// something has to give
-public class BoostedQuery extends Query {
- private Query q;
+public final class BoostedQuery extends Query {
+ private final Query q;
private final ValueSource boostVal; // optional, can be null
public BoostedQuery(Query subQuery, ValueSource boostVal) {
@@ -54,10 +54,10 @@ public class BoostedQuery extends Query
@Override
public Query rewrite(IndexReader reader) throws IOException {
Query newQ = q.rewrite(reader);
- if (newQ == q) return this;
- BoostedQuery bq = (BoostedQuery)this.clone();
- bq.q = newQ;
- return bq;
+ if (newQ != q) {
+ return new BoostedQuery(newQ, boostVal);
+ }
+ return super.rewrite(reader);
}
@Override
@@ -66,13 +66,11 @@ public class BoostedQuery extends Query
}
private class BoostedWeight extends Weight {
- final IndexSearcher searcher;
Weight qWeight;
Map fcontext;
public BoostedWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
super(BoostedQuery.this);
- this.searcher = searcher;
this.qWeight = searcher.createWeight(q, needsScores);
this.fcontext = ValueSource.newContext(searcher);
boostVal.createWeight(fcontext,searcher);
@@ -85,15 +83,12 @@ public class BoostedQuery extends Query
@Override
public float getValueForNormalization() throws IOException {
- float sum = qWeight.getValueForNormalization();
- sum *= getBoost() * getBoost();
- return sum ;
+ return qWeight.getValueForNormalization();
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- topLevelBoost *= getBoost();
- qWeight.normalize(norm, topLevelBoost);
+ public void normalize(float norm, float boost) {
+ qWeight.normalize(norm, boost);
}
@Override
@@ -102,7 +97,7 @@ public class BoostedQuery extends Query
if (subQueryScorer == null) {
return null;
}
- return new BoostedQuery.CustomScorer(context, this, getBoost(), subQueryScorer, boostVal);
+ return new BoostedQuery.CustomScorer(context, this, subQueryScorer, boostVal);
}
@Override
@@ -120,22 +115,20 @@ public class BoostedQuery extends Query
private class CustomScorer extends FilterScorer {
private final BoostedQuery.BoostedWeight weight;
- private final float qWeight;
private final FunctionValues vals;
private final LeafReaderContext readerContext;
- private CustomScorer(LeafReaderContext readerContext, BoostedQuery.BoostedWeight w, float qWeight,
+ private CustomScorer(LeafReaderContext readerContext, BoostedQuery.BoostedWeight w,
Scorer scorer, ValueSource vs) throws IOException {
super(scorer);
this.weight = w;
- this.qWeight = qWeight;
this.readerContext = readerContext;
this.vals = vs.getValues(weight.fcontext, readerContext);
}
@Override
public float score() throws IOException {
- float score = qWeight * in.score() * vals.floatVal(in.docID());
+ float score = in.score() * vals.floatVal(in.docID());
// Current Lucene priority queues can't handle NaN and -Infinity, so
// map to -Float.MAX_VALUE. This conditional handles both -infinity
@@ -164,7 +157,6 @@ public class BoostedQuery extends Query
public String toString(String field) {
StringBuilder sb = new StringBuilder();
sb.append("boost(").append(q.toString(field)).append(',').append(boostVal).append(')');
- sb.append(ToStringUtils.boost(getBoost()));
return sb.toString();
}
@@ -178,11 +170,9 @@ public class BoostedQuery extends Query
@Override
public int hashCode() {
- int h = q.hashCode();
- h ^= (h << 17) | (h >>> 16);
- h += boostVal.hashCode();
- h ^= (h << 8) | (h >>> 25);
- h += Float.floatToIntBits(getBoost());
+ int h = super.hashCode();
+ h = 31 * h + q.hashCode();
+ h = 31 * h + boostVal.hashCode();
return h;
}
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java Mon Sep 7 13:34:46 2015
@@ -53,15 +53,9 @@ public class FunctionQuery extends Query
return func;
}
- @Override
- public Query rewrite(IndexReader reader) throws IOException {
- return this;
- }
-
protected class FunctionWeight extends Weight {
protected final IndexSearcher searcher;
- protected float queryNorm;
- protected float queryWeight;
+ protected float queryNorm = 1f;
protected final Map context;
public FunctionWeight(IndexSearcher searcher) throws IOException {
@@ -76,24 +70,22 @@ public class FunctionQuery extends Query
@Override
public float getValueForNormalization() throws IOException {
- queryWeight = getBoost();
- return queryWeight * queryWeight;
+ return queryNorm * queryNorm;
}
@Override
- public void normalize(float norm, float topLevelBoost) {
- this.queryNorm = norm * topLevelBoost;
- queryWeight *= this.queryNorm;
+ public void normalize(float norm, float boost) {
+ this.queryNorm = norm * boost;
}
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
- return new AllScorer(context, this, queryWeight);
+ return new AllScorer(context, this, queryNorm);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- return ((AllScorer)scorer(context)).explain(doc);
+ return ((AllScorer)scorer(context)).explain(doc, queryNorm);
}
}
@@ -157,13 +149,13 @@ public class FunctionQuery extends Query
return 1;
}
- public Explanation explain(int doc) throws IOException {
+ public Explanation explain(int doc, float queryNorm) throws IOException {
float sc = qWeight * vals.floatVal(doc);
return Explanation.match(sc, "FunctionQuery(" + func + "), product of:",
vals.explain(doc),
- Explanation.match(getBoost(), "boost"),
- Explanation.match(weight.queryNorm, "queryNorm"));
+ Explanation.match(queryNorm, "boost"),
+ Explanation.match(weight.queryNorm = 1f, "queryNorm"));
}
}
@@ -179,9 +171,7 @@ public class FunctionQuery extends Query
@Override
public String toString(String field)
{
- float boost = getBoost();
- return (boost!=1.0?"(":"") + func.toString()
- + (boost==1.0 ? "" : ")^"+boost);
+ return func.toString();
}
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java Mon Sep 7 13:34:46 2015
@@ -29,6 +29,7 @@ import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.similarities.DefaultSimilarity;
@@ -618,14 +619,14 @@ public final class MoreLikeThis {
float bestScore = -1;
while ((scoreTerm = q.pop()) != null) {
- TermQuery tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));
+ Query tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));
if (boost) {
if (bestScore == -1) {
bestScore = (scoreTerm.score);
}
float myScore = (scoreTerm.score);
- tq.setBoost(boostFactor * myScore / bestScore);
+ tq = new BoostQuery(tq, boostFactor * myScore / bestScore);
}
try {
Modified: lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java Mon Sep 7 13:34:46 2015
@@ -78,9 +78,7 @@ public class MoreLikeThisQuery extends Q
}
//make at least half the terms match
newBq.setMinimumNumberShouldMatch((int) (bq.clauses().size() * percentTermsToMatch));
- Query rewritten = newBq.build();
- rewritten.setBoost(bq.getBoost());
- return rewritten;
+ return newBq.build();
}
/* (non-Javadoc)
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java Mon Sep 7 13:34:46 2015
@@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexRead
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
@@ -47,9 +48,10 @@ public class BoostingQueryTest extends L
public void testRewrite() throws IOException {
IndexReader reader = new MultiReader();
BoostingQuery q = new BoostingQuery(new MatchNoDocsQuery(), new MatchAllDocsQuery(), 3);
- Query rewritten = q.rewrite(reader);
+ Query rewritten = new IndexSearcher(reader).rewrite(q);
Query expectedRewritten = new BoostingQuery(new BooleanQuery.Builder().build(), new MatchAllDocsQuery(), 3);
assertEquals(expectedRewritten, rewritten);
assertSame(rewritten, rewritten.rewrite(reader));
}
+
}
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java Mon Sep 7 13:34:46 2015
@@ -41,6 +41,7 @@ import org.apache.lucene.index.TermsEnum
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
@@ -546,7 +547,7 @@ public class CommonTermsQueryTest extend
protected Query newTermQuery(Term term, TermContext context) {
Query query = super.newTermQuery(term, context);
if (term.text().equals("universe")) {
- query.setBoost(100f);
+ query = new BoostQuery(query, 100f);
}
return query;
}
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java Mon Sep 7 13:34:46 2015
@@ -42,6 +42,7 @@ import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -106,10 +107,8 @@ public class TermsQueryTest extends Luce
bq.add(new TermQuery(t), Occur.SHOULD);
}
final Query q1 = new ConstantScoreQuery(bq.build());
- q1.setBoost(boost);
final Query q2 = new TermsQuery(queryTerms);
- q2.setBoost(boost);
- assertSameMatches(searcher, q1, q2, true);
+ assertSameMatches(searcher, new BoostQuery(q1, boost), new BoostQuery(q2, boost), true);
}
reader.close();
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java Mon Sep 7 13:34:46 2015
@@ -23,6 +23,7 @@ import org.apache.lucene.queries.functio
import org.apache.lucene.search.BaseExplanationTestCase;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
@@ -37,8 +38,7 @@ public class TestCustomScoreExplanations
public void testBoost() throws Exception {
Query q = new TermQuery(new Term(FIELD, "w1"));
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
- csq.setBoost(4);
- qtest(csq, new int[] { 0,1,2,3 });
+ qtest(new BoostQuery(csq, 4), new int[] { 0,1,2,3 });
}
public void testTopLevelBoost() throws Exception {
@@ -48,7 +48,6 @@ public class TestCustomScoreExplanations
bqB.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bqB.add(csq, BooleanClause.Occur.MUST);
BooleanQuery bq = bqB.build();
- bq.setBoost(6);
- qtest(bq, new int[] { 0,1,2,3 });
+ qtest(new BoostQuery(bq, 6), new int[] { 0,1,2,3 });
}
}
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java Mon Sep 7 13:34:46 2015
@@ -34,6 +34,7 @@ import org.apache.lucene.queries.functio
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.CheckHits;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
@@ -236,30 +237,41 @@ public class TestCustomScoreQuery extend
BooleanQuery.Builder q2CustomNeutralB = new BooleanQuery.Builder();
q2CustomNeutralB.setDisableCoord(true);
Query q2CustomNeutralInner = new CustomScoreQuery(q1);
- q2CustomNeutralInner.setBoost((float)Math.sqrt(dboost));
- q2CustomNeutralB.add(q2CustomNeutralInner, BooleanClause.Occur.SHOULD);
+ q2CustomNeutralB.add(new BoostQuery(q2CustomNeutralInner, (float)Math.sqrt(dboost)), BooleanClause.Occur.SHOULD);
// a little tricky: we split the boost across an outer BQ and CustomScoreQuery
// this ensures boosting is correct across all these functions (see LUCENE-4935)
Query q2CustomNeutral = q2CustomNeutralB.build();
- q2CustomNeutral.setBoost((float)Math.sqrt(dboost));
+ q2CustomNeutral = new BoostQuery(q2CustomNeutral, (float)Math.sqrt(dboost));
log(q2CustomNeutral);
// custom query, that should (by default) multiply the scores of q1 by that of the field
- CustomScoreQuery q3CustomMul = new CustomScoreQuery(q1, functionQuery);
- q3CustomMul.setStrict(true);
- q3CustomMul.setBoost(boost);
+ Query q3CustomMul;
+ {
+ CustomScoreQuery csq = new CustomScoreQuery(q1, functionQuery);
+ csq.setStrict(true);
+ q3CustomMul = csq;
+ }
+ q3CustomMul = new BoostQuery(q3CustomMul, boost);
log(q3CustomMul);
// custom query, that should add the scores of q1 to that of the field
- CustomScoreQuery q4CustomAdd = new CustomAddQuery(q1, functionQuery);
- q4CustomAdd.setStrict(true);
- q4CustomAdd.setBoost(boost);
+ Query q4CustomAdd;
+ {
+ CustomScoreQuery csq = new CustomAddQuery(q1, functionQuery);
+ csq.setStrict(true);
+ q4CustomAdd = csq;
+ }
+ q4CustomAdd = new BoostQuery(q4CustomAdd, boost);
log(q4CustomAdd);
// custom query, that multiplies and adds the field score to that of q1
- CustomScoreQuery q5CustomMulAdd = new CustomMulAddQuery(q1, functionQuery, functionQuery);
- q5CustomMulAdd.setStrict(true);
- q5CustomMulAdd.setBoost(boost);
+ Query q5CustomMulAdd;
+ {
+ CustomScoreQuery csq = new CustomMulAddQuery(q1, functionQuery, functionQuery);
+ csq.setStrict(true);
+ q5CustomMulAdd = csq;
+ }
+ q5CustomMulAdd = new BoostQuery(q5CustomMulAdd, boost);
log(q5CustomMulAdd);
// do al the searches
Added: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java?rev=1701621&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java (added)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java Mon Sep 7 13:34:46 2015
@@ -0,0 +1,36 @@
+package org.apache.lucene.queries.function;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.queries.function.valuesource.ConstValueSource;
+import org.apache.lucene.search.BaseExplanationTestCase;
+import org.apache.lucene.search.BoostQuery;
+import org.apache.lucene.search.Query;
+
+public class TestFunctionQueryExplanations extends BaseExplanationTestCase {
+
+ public void testSimple() throws Exception {
+ Query q = new FunctionQuery(new ConstValueSource(5));
+ qtest(q, new int[] { 0,1,2,3 });
+ }
+
+ public void testBoost() throws Exception {
+ Query q = new BoostQuery(new FunctionQuery(new ConstValueSource(5)), 2);
+ qtest(q, new int[] { 0,1,2,3 });
+ }
+}
Modified: lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java (original)
+++ lucene/dev/trunk/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java Mon Sep 7 13:34:46 2015
@@ -34,6 +34,7 @@ import org.apache.lucene.index.RandomInd
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
@@ -109,13 +110,14 @@ public class TestMoreLikeThis extends Lu
originalValues.size(), clauses.size());
for (BooleanClause clause : clauses) {
- TermQuery tq = (TermQuery) clause.getQuery();
+ BoostQuery bq = (BoostQuery) clause.getQuery();
+ TermQuery tq = (TermQuery) bq.getQuery();
Float termBoost = originalValues.get(tq.getTerm().text());
assertNotNull("Expected term " + tq.getTerm().text(), termBoost);
float totalBoost = termBoost * boostFactor;
assertEquals("Expected boost of " + totalBoost + " for term '"
- + tq.getTerm().text() + "' got " + tq.getBoost(), totalBoost, tq
+ + tq.getTerm().text() + "' got " + bq.getBoost(), totalBoost, bq
.getBoost(), 0.0001);
}
analyzer.close();
@@ -136,8 +138,9 @@ public class TestMoreLikeThis extends Lu
Collection<BooleanClause> clauses = query.clauses();
for (BooleanClause clause : clauses) {
- TermQuery tq = (TermQuery) clause.getQuery();
- originalValues.put(tq.getTerm().text(), tq.getBoost());
+ BoostQuery bq = (BoostQuery) clause.getQuery();
+ TermQuery tq = (TermQuery) bq.getQuery();
+ originalValues.put(tq.getTerm().text(), bq.getBoost());
}
analyzer.close();
return originalValues;
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java Mon Sep 7 13:34:46 2015
@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
@@ -106,7 +107,7 @@ public class MultiFieldQueryParser exten
//Get the boost from the map and apply them
Float boost = boosts.get(fields[i]);
if (boost != null) {
- q.setBoost(boost.floatValue());
+ q = new BoostQuery(q, boost.floatValue());
}
}
q = applySlop(q,slop);
@@ -133,7 +134,6 @@ public class MultiFieldQueryParser exten
builder.add(terms[i], positions[i]);
}
q = builder.build();
- q.setBoost(pq.getBoost());
} else if (q instanceof MultiPhraseQuery) {
((MultiPhraseQuery) q).setSlop(slop);
}
@@ -153,7 +153,7 @@ public class MultiFieldQueryParser exten
//Get the boost from the map and apply them
Float boost = boosts.get(fields[i]);
if (boost != null) {
- q.setBoost(boost.floatValue());
+ q = new BoostQuery(q, boost.floatValue());
}
}
clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java Mon Sep 7 13:34:46 2015
@@ -503,7 +503,6 @@ public abstract class QueryParserBase ex
builder.add(terms[i], positions[i]);
}
query = builder.build();
- query.setBoost(pq.getBoost());
}
if (query instanceof MultiPhraseQuery) {
((MultiPhraseQuery) query).setSlop(slop);
@@ -902,7 +901,7 @@ public abstract class QueryParserBase ex
// avoid boosting null queries, such as those caused by stop words
if (q != null) {
- q.setBoost(f);
+ q = new BoostQuery(q, f);
}
}
return q;
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java Mon Sep 7 13:34:46 2015
@@ -29,11 +29,13 @@ import org.apache.lucene.queryparser.cla
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanNotQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
@@ -278,6 +280,10 @@ public class ComplexPhraseQueryParser ex
numNegatives++;
}
+ while (qc instanceof BoostQuery) {
+ qc = ((BoostQuery) qc).getQuery();
+ }
+
if (qc instanceof BooleanQuery) {
ArrayList<SpanQuery> sc = new ArrayList<>();
addComplexPhraseClause(sc, (BooleanQuery) qc);
@@ -347,6 +353,13 @@ public class ComplexPhraseQueryParser ex
for (BooleanClause clause : qc) {
Query childQuery = clause.getQuery();
+ float boost = 1f;
+ while (childQuery instanceof BoostQuery) {
+ BoostQuery bq = (BoostQuery) childQuery;
+ boost *= bq.getBoost();
+ childQuery = bq.getQuery();
+ }
+
// select the list to which we will add these options
ArrayList<SpanQuery> chosenList = ors;
if (clause.getOccur() == BooleanClause.Occur.MUST_NOT) {
@@ -355,8 +368,10 @@ public class ComplexPhraseQueryParser ex
if (childQuery instanceof TermQuery) {
TermQuery tq = (TermQuery) childQuery;
- SpanTermQuery stq = new SpanTermQuery(tq.getTerm());
- stq.setBoost(tq.getBoost());
+ SpanQuery stq = new SpanTermQuery(tq.getTerm());
+ if (boost != 1f) {
+ stq = new SpanBoostQuery(stq, boost);
+ }
chosenList.add(stq);
} else if (childQuery instanceof BooleanQuery) {
BooleanQuery cbq = (BooleanQuery) childQuery;
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java Mon Sep 7 13:34:46 2015
@@ -21,6 +21,7 @@ import org.apache.lucene.queryparser.fle
import org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder;
import org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode;
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
/**
@@ -46,9 +47,8 @@ public class BoostQueryNodeBuilder imple
Query query = (Query) child
.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
- query.setBoost(boostNode.getValue());
- return query;
+ return new BoostQuery(query, boostNode.getValue());
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java Mon Sep 7 13:34:46 2015
@@ -54,7 +54,6 @@ public class SlopQueryNodeBuilder implem
builder.add(terms[i], positions[i]);
}
query = builder.build();
- query.setBoost(pq.getBoost());
} else {
((MultiPhraseQuery) query).setSlop(phraseSlopNode.getValue());
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java Mon Sep 7 13:34:46 2015
@@ -21,6 +21,7 @@ import org.apache.lucene.analysis.Analyz
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
@@ -534,7 +535,10 @@ public class SimpleQueryParser extends Q
for (Map.Entry<String,Float> entry : weights.entrySet()) {
Query q = createBooleanQuery(entry.getKey(), text, defaultOperator);
if (q != null) {
- q.setBoost(entry.getValue());
+ float boost = entry.getValue();
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
+ }
bq.add(q, BooleanClause.Occur.SHOULD);
}
}
@@ -549,10 +553,11 @@ public class SimpleQueryParser extends Q
bq.setDisableCoord(true);
for (Map.Entry<String,Float> entry : weights.entrySet()) {
Query q = new FuzzyQuery(new Term(entry.getKey(), text), fuzziness);
- if (q != null) {
- q.setBoost(entry.getValue());
- bq.add(q, BooleanClause.Occur.SHOULD);
+ float boost = entry.getValue();
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
}
+ bq.add(q, BooleanClause.Occur.SHOULD);
}
return simplify(bq.build());
}
@@ -566,7 +571,10 @@ public class SimpleQueryParser extends Q
for (Map.Entry<String,Float> entry : weights.entrySet()) {
Query q = createPhraseQuery(entry.getKey(), text, slop);
if (q != null) {
- q.setBoost(entry.getValue());
+ float boost = entry.getValue();
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
+ }
bq.add(q, BooleanClause.Occur.SHOULD);
}
}
@@ -580,9 +588,12 @@ public class SimpleQueryParser extends Q
BooleanQuery.Builder bq = new BooleanQuery.Builder();
bq.setDisableCoord(true);
for (Map.Entry<String,Float> entry : weights.entrySet()) {
- PrefixQuery prefix = new PrefixQuery(new Term(entry.getKey(), text));
- prefix.setBoost(entry.getValue());
- bq.add(prefix, BooleanClause.Occur.SHOULD);
+ Query q = new PrefixQuery(new Term(entry.getKey(), text));
+ float boost = entry.getValue();
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
+ }
+ bq.add(q, BooleanClause.Occur.SHOULD);
}
return simplify(bq.build());
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java Mon Sep 7 13:34:46 2015
@@ -68,7 +68,6 @@ public class DistanceQuery extends Compo
public void addSpanQueries(SpanNearClauseFactory sncf) throws IOException {
Query snq = getSpanNearQuery(sncf.getIndexReader(),
sncf.getFieldName(),
- getWeight(),
sncf.getBasicQueryFactory());
sncf.addSpanQuery(snq);
}
@@ -76,7 +75,6 @@ public class DistanceQuery extends Compo
public Query getSpanNearQuery(
IndexReader reader,
String fieldName,
- float boost,
BasicQueryFactory qf) throws IOException {
SpanQuery[] spanClauses = new SpanQuery[getNrSubQueries()];
Iterator<?> sqi = getSubQueriesIterator();
@@ -97,9 +95,7 @@ public class DistanceQuery extends Compo
qi++;
}
- SpanNearQuery r = new SpanNearQuery(spanClauses, getOpDistance() - 1, subQueriesOrdered());
- r.setBoost(boost);
- return r;
+ return new SpanNearQuery(spanClauses, getOpDistance() - 1, subQueriesOrdered());
}
@Override
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java Mon Sep 7 13:34:46 2015
@@ -32,7 +32,7 @@ class DistanceRewriteQuery extends Rewri
@Override
public Query rewrite(IndexReader reader) throws IOException {
- return srndQuery.getSpanNearQuery(reader, fieldName, getBoost(), qf);
+ return srndQuery.getSpanNearQuery(reader, fieldName, qf);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java Mon Sep 7 13:34:46 2015
@@ -60,6 +60,7 @@ import org.apache.lucene.index.IndexRead
import org.apache.lucene.index.Term;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
@@ -110,7 +111,13 @@ public class SpanNearClauseFactory { //
return;
if (! (q instanceof SpanQuery))
throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName()));
- addSpanQueryWeighted((SpanQuery)q, q.getBoost());
+ float boost = 1f;
+ if (q instanceof SpanBoostQuery) {
+ SpanBoostQuery bq = (SpanBoostQuery) q;
+ boost = bq.getBoost();
+ q = bq.getQuery();
+ }
+ addSpanQueryWeighted((SpanQuery)q, boost);
}
public SpanQuery makeSpanClause() {
@@ -119,7 +126,10 @@ public class SpanNearClauseFactory { //
int i = 0;
while (sqi.hasNext()) {
SpanQuery sq = sqi.next();
- sq.setBoost(weightBySpanQuery.get(sq).floatValue());
+ float boost = weightBySpanQuery.get(sq);
+ if (boost != 1f) {
+ sq = new SpanBoostQuery(sq, boost);
+ }
spanQueries[i++] = sq;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java Mon Sep 7 13:34:46 2015
@@ -16,8 +16,7 @@ package org.apache.lucene.queryparser.su
* limitations under the License.
*/
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
/** Lowest level base class for surround queries */
@@ -47,7 +46,7 @@ public abstract class SrndQuery implemen
public Query makeLuceneQueryField(String fieldName, BasicQueryFactory qf){
Query q = makeLuceneQueryFieldNoBoost(fieldName, qf);
if (isWeighted()) {
- q.setBoost(getWeight() * q.getBoost()); /* weight may be at any level in a SrndQuery */
+ q = new BoostQuery(q, getWeight()); /* weight may be at any level in a SrndQuery */
}
return q;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -5,6 +5,7 @@ package org.apache.lucene.queryparser.xm
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryparser.xml.DOMUtils;
import org.apache.lucene.queryparser.xml.ParserException;
@@ -63,8 +64,11 @@ public class BooleanQueryBuilder impleme
}
}
- BooleanQuery q = bq.build();
- q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ Query q = bq.build();
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
+ }
return q;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,6 +1,7 @@
package org.apache.lucene.queryparser.xml.builders;
import org.apache.lucene.queries.BoostingQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryparser.xml.DOMUtils;
import org.apache.lucene.queryparser.xml.ParserException;
@@ -47,10 +48,12 @@ public class BoostingQueryBuilder implem
boostQueryElem = DOMUtils.getFirstChildOrFail(boostQueryElem);
Query boostQuery = factory.getQuery(boostQueryElem);
- BoostingQuery bq = new BoostingQuery(mainQuery, boostQuery, boost);
+ Query bq = new BoostingQuery(mainQuery, boostQuery, boost);
- bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ return new BoostQuery(bq, boost);
+ }
return bq;
-
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java Mon Sep 7 13:34:46 2015
@@ -5,6 +5,7 @@ import org.apache.lucene.queryparser.xml
import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadScoreQuery;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.w3c.dom.Element;
@@ -36,9 +37,9 @@ public class BoostingTermBuilder extends
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
- PayloadScoreQuery btq = new PayloadScoreQuery(new SpanTermQuery(new Term(fieldName, value)),
+ SpanQuery btq = new PayloadScoreQuery(new SpanTermQuery(new Term(fieldName, value)),
new AveragePayloadFunction());
- btq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ btq = new SpanBoostQuery(btq, DOMUtils.getAttribute(e, "boost", 1.0f));
return btq;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/ConstantScoreQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/ConstantScoreQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/ConstantScoreQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/ConstantScoreQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -4,6 +4,7 @@ import org.apache.lucene.queryparser.xml
import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.queryparser.xml.QueryBuilder;
import org.apache.lucene.queryparser.xml.QueryBuilderFactory;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query;
import org.w3c.dom.Element;
@@ -40,7 +41,10 @@ public class ConstantScoreQueryBuilder i
Element queryElem = DOMUtils.getFirstChildOrFail(e);
Query q = new ConstantScoreQuery(queryFactory.getQuery(queryElem));
- q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ q = new BoostQuery(q, boost);
+ }
return q;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.queryparser.xm
import org.apache.lucene.queryparser.xml.DOMUtils;
import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.queryparser.xml.QueryBuilder;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.Query;
import org.w3c.dom.Element;
@@ -44,7 +45,6 @@ public class DisjunctionMaxQueryBuilder
public Query getQuery(Element e) throws ParserException {
float tieBreaker = DOMUtils.getAttribute(e, "tieBreaker", 0.0f);
DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);
- dq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
NodeList nl = e.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@@ -56,6 +56,11 @@ public class DisjunctionMaxQueryBuilder
}
}
- return dq;
+ Query q = dq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ q = new BoostQuery(dq, boost);
+ }
+ return q;
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -6,6 +6,7 @@ import org.apache.lucene.queryparser.xml
import org.apache.lucene.queryparser.xml.QueryBuilder;
import org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery;
import org.apache.lucene.sandbox.queries.SlowFuzzyQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -60,8 +61,12 @@ public class FuzzyLikeThisQueryBuilder i
fbq.addTerms(value, fieldName, minSimilarity, prefixLength);
}
- fbq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return fbq;
+ Query q = fbq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ q = new BoostQuery(fbq, boost);
+ }
+ return q;
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LikeThisQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LikeThisQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LikeThisQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LikeThisQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -12,6 +12,7 @@ import org.apache.lucene.analysis.TokenS
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.queries.mlt.MoreLikeThisQuery;
import org.apache.lucene.queryparser.xml.QueryBuilder;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryparser.xml.DOMUtils;
import org.apache.lucene.queryparser.xml.ParserException;
@@ -98,9 +99,12 @@ public class LikeThisQueryBuilder implem
mlt.setMinDocFreq(minDocFreq);
}
- mlt.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
-
- return mlt;
+ Query q = mlt;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ q = new BoostQuery(mlt, boost);
+ }
+ return q;
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,5 +1,6 @@
package org.apache.lucene.queryparser.xml.builders;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanFirstQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -41,8 +42,8 @@ public class SpanFirstBuilder extends Sp
SpanFirstQuery sfq = new SpanFirstQuery(q, end);
- sfq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return sfq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(sfq, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,5 +1,6 @@
package org.apache.lucene.queryparser.xml.builders;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -49,7 +50,9 @@ public class SpanNearBuilder extends Spa
}
}
SpanQuery[] spanQueries = spans.toArray(new SpanQuery[spans.size()]);
- return new SpanNearQuery(spanQueries, slop, inOrder);
+ SpanQuery snq = new SpanNearQuery(spanQueries, slop, inOrder);
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(snq, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,5 +1,6 @@
package org.apache.lucene.queryparser.xml.builders;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanNotQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -46,8 +47,8 @@ public class SpanNotBuilder extends Span
SpanNotQuery snq = new SpanNotQuery(include, exclude);
- snq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return snq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(snq, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,5 +1,6 @@
package org.apache.lucene.queryparser.xml.builders;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -48,8 +49,8 @@ public class SpanOrBuilder extends SpanB
}
SpanQuery[] clauses = clausesList.toArray(new SpanQuery[clausesList.size()]);
SpanOrQuery soq = new SpanOrQuery(clauses);
- soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return soq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(soq, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrTermsBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrTermsBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrTermsBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanOrTermsBuilder.java Mon Sep 7 13:34:46 2015
@@ -4,6 +4,7 @@ import org.apache.lucene.analysis.Analyz
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
@@ -60,8 +61,8 @@ public class SpanOrTermsBuilder extends
}
ts.end();
SpanOrQuery soq = new SpanOrQuery(clausesList.toArray(new SpanQuery[clausesList.size()]));
- soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return soq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(soq, boost);
}
catch (IOException ioe) {
throw new ParserException("IOException parsing value:" + value);
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -15,6 +15,7 @@ package org.apache.lucene.queryparser.xm
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.queryparser.xml.QueryBuilder;
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanTermBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanTermBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanTermBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/SpanTermBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,6 +1,7 @@
package org.apache.lucene.queryparser.xml.builders;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -34,8 +35,8 @@ public class SpanTermBuilder extends Spa
String value = DOMUtils.getNonBlankTextOrFail(e);
SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, value));
- stq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return stq;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new SpanBoostQuery(stq, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -1,6 +1,7 @@
package org.apache.lucene.queryparser.xml.builders;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.queryparser.xml.DOMUtils;
@@ -33,8 +34,11 @@ public class TermQueryBuilder implements
public Query getQuery(Element e) throws ParserException {
String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
- TermQuery tq = new TermQuery(new Term(field, value));
- tq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ Query tq = new TermQuery(new Term(field, value));
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ if (boost != 1f) {
+ tq = new BoostQuery(tq, boost);
+ }
return tq;
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermsQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermsQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermsQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/TermsQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -6,6 +6,7 @@ import org.apache.lucene.analysis.tokena
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
@@ -67,8 +68,8 @@ public class TermsQueryBuilder implement
}
Query q = bq.build();
- q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return q;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new BoostQuery(q, boost);
}
}
Modified: lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/UserInputQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/UserInputQueryBuilder.java?rev=1701621&r1=1701620&r2=1701621&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/UserInputQueryBuilder.java (original)
+++ lucene/dev/trunk/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/UserInputQueryBuilder.java Mon Sep 7 13:34:46 2015
@@ -3,8 +3,8 @@ package org.apache.lucene.queryparser.xm
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.util.Version;
import org.apache.lucene.queryparser.xml.DOMUtils;
import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.queryparser.xml.QueryBuilder;
@@ -73,8 +73,8 @@ public class UserInputQueryBuilder imple
QueryParser parser = createQueryParser(fieldName, analyzer);
q = parser.parse(text);
}
- q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
- return q;
+ float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
+ return new BoostQuery(q, boost);
} catch (ParseException e1) {
throw new ParserException(e1.getMessage());
}