You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/07/21 13:37:25 UTC
[03/51] [abbrv] lucene-solr:apiv2: LUCENE-7368: Remove queryNorm.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
index 289f833..8781d1e 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
@@ -61,8 +61,8 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new W(this, toQuery.createWeight(searcher, false));
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new W(this, toQuery.createWeight(searcher, false, 1f));
}
@Override
@@ -142,17 +142,6 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
}
@Override
- public float getValueForNormalization() throws IOException {
- return 1f;
- }
-
- @Override
- public void normalize(float norm, float boost) {
- // no normalization, we ignore the normalization process
- // and produce scores based on the join
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
if (values == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java
index d83bc8f..5018e97 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java
@@ -118,8 +118,7 @@ abstract class PointInSetIncludingScoreQuery extends Query {
}
@Override
- public final Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- final Weight originalWeight = originalQuery.createWeight(searcher, needsScores);
+ public final Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new Weight(this) {
@Override
@@ -139,16 +138,6 @@ abstract class PointInSetIncludingScoreQuery extends Query {
}
@Override
- public float getValueForNormalization() throws IOException {
- return originalWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- originalWeight.normalize(norm, boost);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
LeafReader reader = context.reader();
PointValues values = reader.getPointValues();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
index 94df35b..3b03bd3 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
@@ -106,8 +106,7 @@ class TermsIncludingScoreQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- final Weight originalWeight = originalQuery.createWeight(searcher, needsScores);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new Weight(TermsIncludingScoreQuery.this) {
@Override
@@ -134,16 +133,6 @@ class TermsIncludingScoreQuery extends Query {
}
@Override
- public float getValueForNormalization() throws IOException {
- return originalWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- originalWeight.normalize(norm, boost);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
Terms terms = context.reader().terms(field);
if (terms == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
index f3d487f..b925b31 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
@@ -81,8 +81,8 @@ public class ToChildBlockJoinQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new ToChildBlockJoinWeight(this, parentQuery.createWeight(searcher, needsScores), parentsFilter, needsScores);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new ToChildBlockJoinWeight(this, parentQuery.createWeight(searcher, needsScores, boost), parentsFilter, needsScores);
}
/** Return our parent query. */
@@ -107,16 +107,6 @@ public class ToChildBlockJoinQuery extends Query {
parentWeight.extractTerms(terms);
}
- @Override
- public float getValueForNormalization() throws IOException {
- return parentWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- parentWeight.normalize(norm, boost);
- }
-
// NOTE: acceptDocs applies (and is checked) only in the
// child document space
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
index e4e099f..d5745d9 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
@@ -115,8 +115,8 @@ public class ToParentBlockJoinQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new BlockJoinWeight(this, childQuery.createWeight(searcher, needsScores), parentsFilter, needsScores ? scoreMode : ScoreMode.None);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new BlockJoinWeight(this, childQuery.createWeight(searcher, needsScores, boost), parentsFilter, needsScores ? scoreMode : ScoreMode.None);
}
/** Return our child query. */
@@ -141,16 +141,6 @@ public class ToParentBlockJoinQuery extends Query {
childWeight.extractTerms(terms);
}
- @Override
- public float getValueForNormalization() throws IOException {
- return childWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- childWeight.normalize(norm, boost);
- }
-
// NOTE: acceptDocs applies (and is checked) only in the
// parent document space
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index 3fc6485..af9ff5c 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -118,13 +118,13 @@ public class TestBlockJoin extends LuceneTestCase {
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
- Weight weight = toParentBlockJoinQuery.createWeight(indexSearcher, false);
+ Weight weight = toParentBlockJoinQuery.createWeight(indexSearcher, false, 1f);
Set<Term> terms = new HashSet<>();
weight.extractTerms(terms);
Term[] termArr =terms.toArray(new Term[0]);
assertEquals(1, termArr.length);
- weight = toChildBlockJoinQuery.createWeight(indexSearcher, false);
+ weight = toChildBlockJoinQuery.createWeight(indexSearcher, false, 1f);
terms = new HashSet<>();
weight.extractTerms(terms);
termArr =terms.toArray(new Term[0]);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
index 5591d5d..b29e9ff 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
@@ -464,8 +464,8 @@ public class TestJoinUtil extends LuceneTestCase {
private final Query fieldQuery = new FieldValueQuery(priceField);
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- Weight fieldWeight = fieldQuery.createWeight(searcher, false);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ Weight fieldWeight = fieldQuery.createWeight(searcher, false, boost);
return new Weight(this) {
@Override
@@ -478,15 +478,6 @@ public class TestJoinUtil extends LuceneTestCase {
}
@Override
- public float getValueForNormalization() throws IOException {
- return 0;
- }
-
- @Override
- public void normalize(float norm, float topLevelBoost) {
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
Scorer fieldScorer = fieldWeight.scorer(context);
if (fieldScorer == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
----------------------------------------------------------------------
diff --git a/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java b/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
index 2f2d4f7..da9fdc5 100644
--- a/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
+++ b/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
@@ -419,9 +419,9 @@ public class TestDiversifiedTopDocsCollector extends LuceneTestCase {
}
@Override
- public SimWeight computeWeight(
+ public SimWeight computeWeight(float boost,
CollectionStatistics collectionStats, TermStatistics... termStats) {
- return sim.computeWeight(collectionStats, termStats);
+ return sim.computeWeight(boost, collectionStats, termStats);
}
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
index 713014c..3bbbf1b 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
@@ -63,12 +63,12 @@ public class BoostingQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
if (needsScores == false) {
- return match.createWeight(searcher, needsScores);
+ return match.createWeight(searcher, needsScores, boost);
}
- final Weight matchWeight = searcher.createWeight(match, needsScores);
- final Weight contextWeight = searcher.createWeight(context, false);
+ final Weight matchWeight = searcher.createWeight(match, needsScores, boost);
+ final Weight contextWeight = searcher.createWeight(context, false, boost);
return new Weight(this) {
@Override
@@ -92,16 +92,6 @@ public class BoostingQuery extends Query {
}
@Override
- public float getValueForNormalization() throws IOException {
- return matchWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- matchWeight.normalize(norm, boost);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
final Scorer matchScorer = matchWeight.scorer(context);
if (matchScorer == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
index ab44fed..2ae6c01 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
@@ -26,7 +26,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.function.FunctionQuery;
-import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.FilterScorer;
import org.apache.lucene.search.IndexSearcher;
@@ -48,7 +47,6 @@ public class CustomScoreQuery extends Query implements Cloneable {
private Query subQuery;
private Query[] scoringQueries; // never null (empty array if there are no valSrcQueries).
- private boolean strict = false; // if true, valueSource part of query does not take part in weights normalization.
/**
* Create a CustomScoreQuery over input subQuery.
@@ -131,7 +129,6 @@ public class CustomScoreQuery extends Query implements Cloneable {
sb.append(", ").append(scoringQuery.toString(field));
}
sb.append(")");
- sb.append(strict?" STRICT" : "");
return sb.toString();
}
@@ -144,7 +141,6 @@ public class CustomScoreQuery extends Query implements Cloneable {
private boolean equalsTo(CustomScoreQuery other) {
return subQuery.equals(other.subQuery) &&
- strict == other.strict &&
scoringQueries.length == other.scoringQueries.length &&
Arrays.equals(scoringQueries, other.scoringQueries);
}
@@ -155,7 +151,7 @@ public class CustomScoreQuery extends Query implements Cloneable {
// Didn't change this hashcode, but it looks suspicious.
return (classHash() +
subQuery.hashCode() +
- Arrays.hashCode(scoringQueries)) ^ (strict ? 1234 : 4321);
+ Arrays.hashCode(scoringQueries));
}
/**
@@ -171,19 +167,23 @@ public class CustomScoreQuery extends Query implements Cloneable {
//=========================== W E I G H T ============================
private class CustomWeight extends Weight {
- Weight subQueryWeight;
- Weight[] valSrcWeights;
- boolean qStrict;
- float queryWeight;
+ final Weight subQueryWeight;
+ final Weight[] valSrcWeights;
+ final float queryWeight;
- public CustomWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public CustomWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
super(CustomScoreQuery.this);
- this.subQueryWeight = subQuery.createWeight(searcher, needsScores);
+ // 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.
+ // so, instead boosts are applied directly in score()
+ this.subQueryWeight = subQuery.createWeight(searcher, needsScores, 1f);
this.valSrcWeights = new Weight[scoringQueries.length];
for(int i = 0; i < scoringQueries.length; i++) {
- this.valSrcWeights[i] = scoringQueries[i].createWeight(searcher, needsScores);
+ this.valSrcWeights[i] = scoringQueries[i].createWeight(searcher, needsScores, 1f);
}
- this.qStrict = strict;
+ this.queryWeight = boost;
}
@Override
@@ -195,36 +195,6 @@ public class CustomScoreQuery extends Query implements Cloneable {
}
@Override
- public float getValueForNormalization() throws IOException {
- float sum = subQueryWeight.getValueForNormalization();
- for (Weight valSrcWeight : valSrcWeights) {
- if (qStrict == false) { // otherwise do not include ValueSource part in the query normalization
- sum += valSrcWeight.getValueForNormalization();
- }
- }
- return sum;
- }
-
- /*(non-Javadoc) @see org.apache.lucene.search.Weight#normalize(float) */
- @Override
- 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.
- // so, instead boosts are applied directly in score()
- subQueryWeight.normalize(norm, 1f);
- for (Weight valSrcWeight : valSrcWeights) {
- if (qStrict) {
- valSrcWeight.normalize(1, 1); // do not normalize the ValueSource part
- } else {
- valSrcWeight.normalize(norm, 1f);
- }
- }
- queryWeight = boost;
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
Scorer subQueryScorer = subQueryWeight.scorer(context);
if (subQueryScorer == null) {
@@ -311,30 +281,8 @@ public class CustomScoreQuery extends Query implements Cloneable {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new CustomWeight(searcher, needsScores);
- }
-
- /**
- * Checks if this is strict custom scoring.
- * In strict custom scoring, the {@link ValueSource} part does not participate in weight normalization.
- * This may be useful when one wants full control over how scores are modified, and does
- * not care about normalizing by the {@link ValueSource} part.
- * One particular case where this is useful if for testing this query.
- * <P>
- * Note: only has effect when the {@link ValueSource} part is not null.
- */
- public boolean isStrict() {
- return strict;
- }
-
- /**
- * Set the strict mode of this query.
- * @param strict The strict mode to set.
- * @see #isStrict()
- */
- public void setStrict(boolean strict) {
- this.strict = strict;
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new CustomWeight(searcher, needsScores, boost);
}
/** The sub-query that CustomScoreQuery wraps, affecting both the score and which documents match. */
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
index 5c03b2d..7b7f094 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
@@ -254,8 +254,8 @@ public class TermsQuery extends Query implements Accountable {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new ConstantScoreWeight(this) {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new ConstantScoreWeight(this, boost) {
@Override
public void extractTerms(Set<Term> terms) {
@@ -334,8 +334,7 @@ public class TermsQuery extends Query implements Accountable {
bq.add(new TermQuery(new Term(t.field, t.term), termContext), Occur.SHOULD);
}
Query q = new ConstantScoreQuery(bq.build());
- final Weight weight = searcher.rewrite(q).createWeight(searcher, needsScores);
- weight.normalize(1f, score());
+ final Weight weight = searcher.rewrite(q).createWeight(searcher, needsScores, score());
return new WeightOrDocIdSet(weight);
} else {
assert builder != null;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
index 3d82723..c8b9423 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
@@ -59,17 +59,17 @@ public final class BoostedQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new BoostedQuery.BoostedWeight(searcher, needsScores);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new BoostedQuery.BoostedWeight(searcher, needsScores, boost);
}
private class BoostedWeight extends Weight {
Weight qWeight;
Map fcontext;
- public BoostedWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public BoostedWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
super(BoostedQuery.this);
- this.qWeight = searcher.createWeight(q, needsScores);
+ this.qWeight = searcher.createWeight(q, needsScores, boost);
this.fcontext = ValueSource.newContext(searcher);
boostVal.createWeight(fcontext,searcher);
}
@@ -80,16 +80,6 @@ public final class BoostedQuery extends Query {
}
@Override
- public float getValueForNormalization() throws IOException {
- return qWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float norm, float boost) {
- qWeight.normalize(norm, boost);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
Scorer subQueryScorer = qWeight.scorer(context);
if (subQueryScorer == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
index e6152e8..4acb563 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
@@ -55,35 +55,23 @@ public class FunctionQuery extends Query {
protected class FunctionWeight extends Weight {
protected final IndexSearcher searcher;
- protected float queryNorm, boost, queryWeight;
+ protected final float boost;
protected final Map context;
- public FunctionWeight(IndexSearcher searcher) throws IOException {
+ public FunctionWeight(IndexSearcher searcher, float boost) throws IOException {
super(FunctionQuery.this);
this.searcher = searcher;
this.context = ValueSource.newContext(searcher);
func.createWeight(context, searcher);
- normalize(1f, 1f);;
+ this.boost = boost;
}
@Override
public void extractTerms(Set<Term> terms) {}
@Override
- public float getValueForNormalization() throws IOException {
- return queryWeight * queryWeight;
- }
-
- @Override
- public void normalize(float norm, float boost) {
- this.queryNorm = norm;
- this.boost = boost;
- this.queryWeight = norm * boost;
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
- return new AllScorer(context, this, queryWeight);
+ return new AllScorer(context, this, boost);
}
@Override
@@ -96,14 +84,14 @@ public class FunctionQuery extends Query {
final IndexReader reader;
final FunctionWeight weight;
final int maxDoc;
- final float qWeight;
+ final float boost;
final DocIdSetIterator iterator;
final FunctionValues vals;
- public AllScorer(LeafReaderContext context, FunctionWeight w, float qWeight) throws IOException {
+ public AllScorer(LeafReaderContext context, FunctionWeight w, float boost) throws IOException {
super(w);
this.weight = w;
- this.qWeight = qWeight;
+ this.boost = boost;
this.reader = context.reader();
this.maxDoc = reader.maxDoc();
iterator = DocIdSetIterator.all(context.reader().maxDoc());
@@ -122,7 +110,7 @@ public class FunctionQuery extends Query {
@Override
public float score() throws IOException {
- float score = qWeight * vals.floatVal(docID());
+ float score = boost * vals.floatVal(docID());
// Current Lucene priority queues can't handle NaN and -Infinity, so
// map to -Float.MAX_VALUE. This conditional handles both -infinity
@@ -136,20 +124,19 @@ public class FunctionQuery extends Query {
}
public Explanation explain(int doc) throws IOException {
- float sc = qWeight * vals.floatVal(doc);
+ float sc = boost * vals.floatVal(doc);
return Explanation.match(sc, "FunctionQuery(" + func + "), product of:",
vals.explain(doc),
- Explanation.match(weight.boost, "boost"),
- Explanation.match(weight.queryNorm, "queryNorm"));
+ Explanation.match(weight.boost, "boost"));
}
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new FunctionQuery.FunctionWeight(searcher);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new FunctionQuery.FunctionWeight(searcher, boost);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
index 60cfca3..41572a5 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
@@ -114,7 +114,7 @@ public class FunctionRangeQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new FunctionRangeWeight(searcher);
}
@@ -133,17 +133,6 @@ public class FunctionRangeQuery extends Query {
//none
}
- //Note: this uses the functionValue's floatVal() as the score; queryNorm/boost is ignored.
- @Override
- public float getValueForNormalization() throws IOException {
- return 1f;
- }
-
- @Override
- public void normalize(float norm, float topLevelBoost) {
- //no-op
- }
-
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
FunctionValues functionValues = valueSource.getValues(vsContext, context);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
index 2d483ba..5669406 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
@@ -86,11 +86,11 @@ public class PayloadScoreQuery extends SpanQuery {
}
@Override
- public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- SpanWeight innerWeight = wrappedQuery.createWeight(searcher, needsScores);
+ public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ SpanWeight innerWeight = wrappedQuery.createWeight(searcher, needsScores, boost);
if (!needsScores)
return innerWeight;
- return new PayloadSpanWeight(searcher, innerWeight);
+ return new PayloadSpanWeight(searcher, innerWeight, boost);
}
@Override
@@ -116,8 +116,8 @@ public class PayloadScoreQuery extends SpanQuery {
private final SpanWeight innerWeight;
- public PayloadSpanWeight(IndexSearcher searcher, SpanWeight innerWeight) throws IOException {
- super(PayloadScoreQuery.this, searcher, null);
+ public PayloadSpanWeight(IndexSearcher searcher, SpanWeight innerWeight, float boost) throws IOException {
+ super(PayloadScoreQuery.this, searcher, null, boost);
this.innerWeight = innerWeight;
}
@@ -147,16 +147,6 @@ public class PayloadScoreQuery extends SpanQuery {
}
@Override
- public float getValueForNormalization() throws IOException {
- return innerWeight.getValueForNormalization();
- }
-
- @Override
- public void normalize(float queryNorm, float topLevelBoost) {
- innerWeight.normalize(queryNorm, topLevelBoost);
- }
-
- @Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
PayloadSpanScorer scorer = scorer(context);
if (scorer == null || scorer.iterator().advance(doc) != doc)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
index 419a82a..57ba678 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
@@ -59,9 +59,9 @@ public class SpanPayloadCheckQuery extends SpanQuery {
}
@Override
- public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- SpanWeight matchWeight = match.createWeight(searcher, false);
- return new SpanPayloadCheckWeight(searcher, needsScores ? getTermContexts(matchWeight) : null, matchWeight);
+ public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ SpanWeight matchWeight = match.createWeight(searcher, false, boost);
+ return new SpanPayloadCheckWeight(searcher, needsScores ? getTermContexts(matchWeight) : null, matchWeight, boost);
}
/**
@@ -71,8 +71,8 @@ public class SpanPayloadCheckQuery extends SpanQuery {
final SpanWeight matchWeight;
- public SpanPayloadCheckWeight(IndexSearcher searcher, Map<Term, TermContext> termContexts, SpanWeight matchWeight) throws IOException {
- super(SpanPayloadCheckQuery.this, searcher, termContexts);
+ public SpanPayloadCheckWeight(IndexSearcher searcher, Map<Term, TermContext> termContexts, SpanWeight matchWeight, float boost) throws IOException {
+ super(SpanPayloadCheckQuery.this, searcher, termContexts, boost);
this.matchWeight = matchWeight;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java b/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
index c87a004..ab3cced 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
@@ -62,36 +62,30 @@ public class TestCustomScoreExplanations extends BaseExplanationTestCase {
searcher.setSimilarity(new BM25Similarity());
Explanation expl = searcher.explain(query, 0);
+ assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(1f, expl.getDetails()[1].getValue(), 0f);
- // norm
- assertEquals("queryNorm", expl.getDetails()[2].getDescription());
- assertEquals(1f, expl.getDetails()[2].getValue(), 0f);
query = new BoostQuery(query, 2);
expl = searcher.explain(query, 0);
+ assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(2f, expl.getDetails()[1].getValue(), 0f);
- // norm
- assertEquals("queryNorm", expl.getDetails()[2].getDescription());
- assertEquals(1f, expl.getDetails()[2].getValue(), 0f);
searcher.setSimilarity(new ClassicSimilarity()); // in order to have a queryNorm != 1
expl = searcher.explain(query, 0);
+ assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(2f, expl.getDetails()[1].getValue(), 0f);
- // norm
- assertEquals("queryNorm", expl.getDetails()[2].getDescription());
- assertEquals(0.5f, expl.getDetails()[2].getValue(), 0f);
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
index c3ee47d..0caa4ce 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
@@ -246,7 +246,6 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
Query q3CustomMul;
{
CustomScoreQuery csq = new CustomScoreQuery(q1, functionQuery);
- csq.setStrict(true);
q3CustomMul = csq;
}
q3CustomMul = new BoostQuery(q3CustomMul, boost);
@@ -256,7 +255,6 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
Query q4CustomAdd;
{
CustomScoreQuery csq = new CustomAddQuery(q1, functionQuery);
- csq.setStrict(true);
q4CustomAdd = csq;
}
q4CustomAdd = new BoostQuery(q4CustomAdd, boost);
@@ -266,7 +264,6 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
Query q5CustomMulAdd;
{
CustomScoreQuery csq = new CustomMulAddQuery(q1, functionQuery, functionQuery);
- csq.setStrict(true);
q5CustomMulAdd = csq;
}
q5CustomMulAdd = new BoostQuery(q5CustomMulAdd, boost);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java
index 4518699..cfebc47 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java
@@ -124,12 +124,6 @@ class PreciseClassicSimilarity extends TFIDFSimilarity {
/** Sole constructor: parameter-free */
public PreciseClassicSimilarity() {}
- /** Implemented as <code>1/sqrt(sumOfSquaredWeights)</code>. */
- @Override
- public float queryNorm(float sumOfSquaredWeights) {
- return (float)(1.0 / Math.sqrt(sumOfSquaredWeights));
- }
-
/**
* Encodes a normalization factor for storage in an index.
* <p>
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
index 7429797..188ef61 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadScoreQuery.java
@@ -262,11 +262,6 @@ public class TestPayloadScoreQuery extends LuceneTestCase {
static class BoostingSimilarity extends MultiplyingSimilarity {
- @Override
- public float queryNorm(float sumOfSquaredWeights) {
- return 1.0f;
- }
-
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Make everything else 1 so we see the effect of the payload
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java
index 2c0204d..3c5b80f 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadSpans.java
@@ -74,12 +74,12 @@ public class TestPayloadSpans extends LuceneTestCase {
Spans spans;
stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "seventy"));
- spans = stq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = stq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 100, 1, 1, 1);
stq = new SpanTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "seventy"));
- spans = stq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = stq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 100, 0, 0, 0);
}
@@ -90,7 +90,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanFirstQuery sfq;
match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
sfq = new SpanFirstQuery(match, 2);
- Spans spans = sfq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ Spans spans = sfq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
checkSpans(spans, 109, 1, 1, 1);
//Test more complicated subclause
SpanQuery[] clauses = new SpanQuery[2];
@@ -98,11 +98,11 @@ public class TestPayloadSpans extends LuceneTestCase {
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "hundred"));
match = new SpanNearQuery(clauses, 0, true);
sfq = new SpanFirstQuery(match, 2);
- checkSpans(sfq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS), 100, 2, 1, 1);
+ checkSpans(sfq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS), 100, 2, 1, 1);
match = new SpanNearQuery(clauses, 0, false);
sfq = new SpanFirstQuery(match, 2);
- checkSpans(sfq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS), 100, 2, 1, 1);
+ checkSpans(sfq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS), 100, 2, 1, 1);
}
@@ -125,7 +125,7 @@ public class TestPayloadSpans extends LuceneTestCase {
IndexReader reader = getOnlyLeafReader(writer.getReader());
writer.close();
- checkSpans(snq.createWeight(newSearcher(reader, false), false).getSpans(reader.leaves().get(0), SpanWeight.Postings.PAYLOADS), 1, new int[]{2});
+ checkSpans(snq.createWeight(newSearcher(reader, false), false, 1f).getSpans(reader.leaves().get(0), SpanWeight.Postings.PAYLOADS), 1, new int[]{2});
reader.close();
directory.close();
}
@@ -136,7 +136,7 @@ public class TestPayloadSpans extends LuceneTestCase {
IndexSearcher searcher = getSearcher();
stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "mark"));
- spans = stq.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = stq.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertNull(spans);
SpanQuery[] clauses = new SpanQuery[3];
@@ -145,7 +145,7 @@ public class TestPayloadSpans extends LuceneTestCase {
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 12, false);
- spans = spanNearQuery.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = spanNearQuery.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 2, new int[]{3,3});
@@ -156,7 +156,7 @@ public class TestPayloadSpans extends LuceneTestCase {
spanNearQuery = new SpanNearQuery(clauses, 6, true);
- spans = spanNearQuery.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = spanNearQuery.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 1, new int[]{3});
@@ -178,7 +178,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses2, 6, false);
// yy within 6 of xx within 6 of rr
- spans = nestedSpanNearQuery.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = nestedSpanNearQuery.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 2, new int[]{3,3});
closeIndexReader.close();
@@ -209,7 +209,7 @@ public class TestPayloadSpans extends LuceneTestCase {
clauses3[1] = snq;
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
- spans = nestedSpanNearQuery.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = nestedSpanNearQuery.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 1, new int[]{3});
@@ -247,7 +247,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
- spans = nestedSpanNearQuery.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ spans = nestedSpanNearQuery.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
assertTrue("spans is null and it shouldn't be", spans != null);
checkSpans(spans, 2, new int[]{8, 8});
closeIndexReader.close();
@@ -272,7 +272,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanQuery[] sqs = { stq1, stq2 };
SpanNearQuery snq = new SpanNearQuery(sqs, 1, true);
VerifyingCollector collector = new VerifyingCollector();
- Spans spans = snq.createWeight(is, false).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ Spans spans = snq.createWeight(is, false, 1f).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
TopDocs topDocs = is.search(snq, 1);
Set<String> payloadSet = new HashSet<>();
@@ -311,7 +311,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanQuery[] sqs = { stq1, stq2 };
SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
VerifyingCollector collector = new VerifyingCollector();
- Spans spans = snq.createWeight(is, false).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ Spans spans = snq.createWeight(is, false, 1f).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
TopDocs topDocs = is.search(snq, 1);
Set<String> payloadSet = new HashSet<>();
@@ -349,7 +349,7 @@ public class TestPayloadSpans extends LuceneTestCase {
SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
SpanQuery[] sqs = { stq1, stq2 };
SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
- Spans spans = snq.createWeight(is, false).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
+ Spans spans = snq.createWeight(is, false, 1f).getSpans(is.getIndexReader().leaves().get(0), SpanWeight.Postings.PAYLOADS);
TopDocs topDocs = is.search(snq, 1);
Set<String> payloadSet = new HashSet<>();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java
index 8f65c1a..9cc7067 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java
@@ -164,7 +164,7 @@ public class TestPayloadTermQuery extends LuceneTestCase {
assertTrue(doc.score + " does not equal: " + 1, doc.score == 1);
}
CheckHits.checkExplanations(query, PayloadHelper.FIELD, searcher, true);
- Spans spans = query.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.POSITIONS);
+ Spans spans = query.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.POSITIONS);
assertTrue("spans is null and it shouldn't be", spans != null);
/*float score = hits.score(0);
for (int i =1; i < hits.length(); i++)
@@ -215,7 +215,7 @@ public class TestPayloadTermQuery extends LuceneTestCase {
}
assertTrue(numTens + " does not equal: " + 10, numTens == 10);
CheckHits.checkExplanations(query, "field", searcher, true);
- Spans spans = query.createWeight(searcher, false).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.POSITIONS);
+ Spans spans = query.createWeight(searcher, false, 1f).getSpans(searcher.getIndexReader().leaves().get(0), SpanWeight.Postings.POSITIONS);
assertTrue("spans is null and it shouldn't be", spans != null);
//should be two matches per document
int count = 0;
@@ -257,11 +257,6 @@ public class TestPayloadTermQuery extends LuceneTestCase {
static class BoostingSimilarity extends ClassicSimilarity {
- @Override
- public float queryNorm(float sumOfSquaredWeights) {
- return 1;
- }
-
// TODO: Remove warning after API has been finalized
@Override
public float scorePayload(int docId, int start, int end, BytesRef payload) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
index d479713..1b20d95 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
@@ -67,7 +67,7 @@ final class LatLonPointDistanceQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
Rectangle box = Rectangle.fromPointDistance(latitude, longitude, radiusMeters);
// create bounding box(es) for the distance range
// these are pre-encoded with LatLonPoint's encoding
@@ -100,7 +100,7 @@ final class LatLonPointDistanceQuery extends Query {
final double axisLat = Rectangle.axisLat(latitude, radiusMeters);
- return new ConstantScoreWeight(this) {
+ return new ConstantScoreWeight(this, boost) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
index 8db8296..036fe2c 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
@@ -74,7 +74,7 @@ final class LatLonPointInPolygonQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
// I don't use RandomAccessWeight here: it's no good to approximate with "match all docs"; this is an inverted structure and should be
// used in the first pass:
@@ -93,7 +93,7 @@ final class LatLonPointInPolygonQuery extends Query {
final Polygon2D tree = Polygon2D.create(polygons);
- return new ConstantScoreWeight(this) {
+ return new ConstantScoreWeight(this, boost) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java
index a588e88..655e9f3 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java
@@ -95,8 +95,8 @@ public class DocValuesNumbersQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new RandomAccessWeight(this) {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new RandomAccessWeight(this, boost) {
@Override
protected Bits getMatchingDocs(LeafReaderContext context) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
index d603040..44f3f8c 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
@@ -139,11 +139,11 @@ public final class DocValuesRangeQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
if (lowerVal == null && upperVal == null) {
throw new IllegalStateException("Both min and max values must not be null, call rewrite first");
}
- return new RandomAccessWeight(DocValuesRangeQuery.this) {
+ return new RandomAccessWeight(DocValuesRangeQuery.this, boost) {
@Override
protected Bits getMatchingDocs(LeafReaderContext context) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesTermsQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
index 7cb2ce1..4be4b18 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
@@ -148,8 +148,8 @@ public class DocValuesTermsQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- return new RandomAccessWeight(this) {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
+ return new RandomAccessWeight(this, boost) {
@Override
protected Bits getMatchingDocs(LeafReaderContext context) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
index b3a7ba2..530a9b6 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
@@ -186,7 +186,7 @@ public class TermAutomatonQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
IndexReaderContext context = searcher.getTopReaderContext();
Map<Integer,TermContext> termStates = new HashMap<>();
@@ -196,7 +196,7 @@ public class TermAutomatonQuery extends Query {
}
}
- return new TermAutomatonWeight(det, searcher, termStates);
+ return new TermAutomatonWeight(det, searcher, termStates, boost);
}
@Override
@@ -332,7 +332,7 @@ public class TermAutomatonQuery extends Query {
private final Similarity.SimWeight stats;
private final Similarity similarity;
- public TermAutomatonWeight(Automaton automaton, IndexSearcher searcher, Map<Integer,TermContext> termStates) throws IOException {
+ public TermAutomatonWeight(Automaton automaton, IndexSearcher searcher, Map<Integer,TermContext> termStates, float boost) throws IOException {
super(TermAutomatonQuery.this);
this.automaton = automaton;
this.termStates = termStates;
@@ -345,7 +345,7 @@ public class TermAutomatonQuery extends Query {
}
}
- stats = similarity.computeWeight(searcher.collectionStatistics(field),
+ stats = similarity.computeWeight(boost, searcher.collectionStatistics(field),
allTermStats.toArray(new TermStatistics[allTermStats.size()]));
}
@@ -364,16 +364,6 @@ public class TermAutomatonQuery extends Query {
}
@Override
- public float getValueForNormalization() {
- return stats.getValueForNormalization();
- }
-
- @Override
- public void normalize(float queryNorm, float boost) {
- stats.normalize(queryNorm, boost);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
// Initialize the enums; null for a given slot means that term didn't appear in this reader
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
index b321494..a8c8b51 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
@@ -80,7 +80,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {
flt.addTerms("smith", "name", 0.3f, 1);
Query q = flt.rewrite(searcher.getIndexReader());
HashSet<Term> queryTerms = new HashSet<>();
- searcher.createWeight(q, true).extractTerms(queryTerms);
+ searcher.createWeight(q, true, 1f).extractTerms(queryTerms);
assertTrue("Should have variant smythe", queryTerms.contains(new Term("name", "smythe")));
assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
assertTrue("Should have variant smyth", queryTerms.contains(new Term("name", "smyth")));
@@ -97,7 +97,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {
flt.addTerms("jonathin smoth", "name", 0.3f, 1);
Query q = flt.rewrite(searcher.getIndexReader());
HashSet<Term> queryTerms = new HashSet<>();
- searcher.createWeight(q, true).extractTerms(queryTerms);
+ searcher.createWeight(q, true, 1f).extractTerms(queryTerms);
assertTrue("Should have variant jonathan", queryTerms.contains(new Term("name", "jonathan")));
assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
TopDocs topDocs = searcher.search(flt, 1);
@@ -115,7 +115,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {
// don't fail here just because the field doesn't exits
Query q = flt.rewrite(searcher.getIndexReader());
HashSet<Term> queryTerms = new HashSet<>();
- searcher.createWeight(q, true).extractTerms(queryTerms);
+ searcher.createWeight(q, true, 1f).extractTerms(queryTerms);
assertTrue("Should have variant jonathan", queryTerms.contains(new Term("name", "jonathan")));
assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
TopDocs topDocs = searcher.search(flt, 1);
@@ -132,7 +132,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {
flt.addTerms("fernando smith", "name", 0.3f, 1);
Query q = flt.rewrite(searcher.getIndexReader());
HashSet<Term> queryTerms = new HashSet<>();
- searcher.createWeight(q, true).extractTerms(queryTerms);
+ searcher.createWeight(q, true, 1f).extractTerms(queryTerms);
assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
TopDocs topDocs = searcher.search(flt, 1);
ScoreDoc[] sd = topDocs.scoreDocs;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5def78ba/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java
deleted file mode 100644
index 84145a1..0000000
--- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.sandbox.queries;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.analysis.MockTokenizer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.MultiTermQuery;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.search.similarities.ClassicSimilarity;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.LuceneTestCase;
-
-/**
- * Tests the results of fuzzy against pre-recorded output
- * The format of the file is the following:
- *
- * Header Row: # of bits: generate 2^n sequential documents
- * with a value of Integer.toBinaryString
- *
- * Entries: an entry is a param spec line, a resultCount line, and
- * then 'resultCount' results lines. The results lines are in the
- * expected order.
- *
- * param spec line: a comma-separated list of params to FuzzyQuery
- * (query, prefixLen, pqSize, minScore)
- * query = query text as a number (expand with Integer.toBinaryString)
- * prefixLen = prefix length
- * pqSize = priority queue maximum size for TopTermsBoostOnlyBooleanQueryRewrite
- * minScore = minimum similarity
- *
- * resultCount line: total number of expected hits.
- *
- * results line: comma-separated docID, score pair
- **/
-public class TestSlowFuzzyQuery2 extends LuceneTestCase {
- /** epsilon for score comparisons */
- static final float epsilon = 0.00001f;
-
- static int[][] mappings = new int[][] {
- new int[] { 0x40, 0x41 },
- new int[] { 0x40, 0x0195 },
- new int[] { 0x40, 0x0906 },
- new int[] { 0x40, 0x1040F },
- new int[] { 0x0194, 0x0195 },
- new int[] { 0x0194, 0x0906 },
- new int[] { 0x0194, 0x1040F },
- new int[] { 0x0905, 0x0906 },
- new int[] { 0x0905, 0x1040F },
- new int[] { 0x1040E, 0x1040F }
- };
- public void testFromTestData() throws Exception {
- // TODO: randomize!
- assertFromTestData(mappings[random().nextInt(mappings.length)]);
- }
-
- public void assertFromTestData(int codePointTable[]) throws Exception {
- if (VERBOSE) {
- System.out.println("TEST: codePointTable=" + codePointTable);
- }
- InputStream stream = getClass().getResourceAsStream("fuzzyTestData.txt");
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
-
- int bits = Integer.parseInt(reader.readLine());
- int terms = (int) Math.pow(2, bits);
-
- Directory dir = newDirectory();
- Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
- RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(analyzer).setMergePolicy(newLogMergePolicy()));
-
- Document doc = new Document();
- Field field = newTextField("field", "", Field.Store.NO);
- doc.add(field);
-
- for (int i = 0; i < terms; i++) {
- field.setStringValue(mapInt(codePointTable, i));
- writer.addDocument(doc);
- }
-
- IndexReader r = writer.getReader();
- IndexSearcher searcher = newSearcher(r);
- if (VERBOSE) {
- System.out.println("TEST: searcher=" + searcher);
- }
- // even though this uses a boost-only rewrite, this test relies upon queryNorm being the default implementation,
- // otherwise scores are different!
- searcher.setSimilarity(new ClassicSimilarity());
-
- writer.close();
- String line;
- while ((line = reader.readLine()) != null) {
- String params[] = line.split(",");
- String query = mapInt(codePointTable, Integer.parseInt(params[0]));
- int prefix = Integer.parseInt(params[1]);
- int pqSize = Integer.parseInt(params[2]);
- float minScore = Float.parseFloat(params[3]);
- SlowFuzzyQuery q = new SlowFuzzyQuery(new Term("field", query), minScore, prefix);
- q.setRewriteMethod(new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite(pqSize));
- int expectedResults = Integer.parseInt(reader.readLine());
- TopDocs docs = searcher.search(q, expectedResults);
- assertEquals(expectedResults, docs.totalHits);
- for (int i = 0; i < expectedResults; i++) {
- String scoreDoc[] = reader.readLine().split(",");
- assertEquals(Integer.parseInt(scoreDoc[0]), docs.scoreDocs[i].doc);
- assertEquals(Float.parseFloat(scoreDoc[1]), docs.scoreDocs[i].score, epsilon);
- }
- }
- IOUtils.close(r, dir, analyzer);
- }
-
- /* map bits to unicode codepoints */
- private static String mapInt(int codePointTable[], int i) {
- StringBuilder sb = new StringBuilder();
- String binary = Integer.toBinaryString(i);
- for (int j = 0; j < binary.length(); j++)
- sb.appendCodePoint(codePointTable[binary.charAt(j) - '0']);
- return sb.toString();
- }
-
- /* Code to generate test data
- public static void main(String args[]) throws Exception {
- int bits = 3;
- System.out.println(bits);
- int terms = (int) Math.pow(2, bits);
-
- RAMDirectory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new KeywordAnalyzer(),
- IndexWriter.MaxFieldLength.UNLIMITED);
-
- Document doc = new Document();
- Field field = newField("field", "", Field.Store.NO, Field.Index.ANALYZED);
- doc.add(field);
-
- for (int i = 0; i < terms; i++) {
- field.setValue(Integer.toBinaryString(i));
- writer.addDocument(doc);
- }
-
- writer.forceMerge(1);
- writer.close();
-
- IndexSearcher searcher = new IndexSearcher(dir);
- for (int prefix = 0; prefix < bits; prefix++)
- for (int pqsize = 1; pqsize <= terms; pqsize++)
- for (float minscore = 0.1F; minscore < 1F; minscore += 0.2F)
- for (int query = 0; query < terms; query++) {
- FuzzyQuery q = new FuzzyQuery(
- new Term("field", Integer.toBinaryString(query)), minscore, prefix);
- q.setRewriteMethod(new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite(pqsize));
- System.out.println(query + "," + prefix + "," + pqsize + "," + minscore);
- TopDocs docs = searcher.search(q, terms);
- System.out.println(docs.totalHits);
- for (int i = 0; i < docs.totalHits; i++)
- System.out.println(docs.scoreDocs[i].doc + "," + docs.scoreDocs[i].score);
- }
- }
- */
-}