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/08 14:16:09 UTC
svn commit: r1701783 [4/6] - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/core/ 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/ l...
Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java Tue Sep 8 12:16:06 2015
@@ -228,6 +228,9 @@ public class HighlighterTest extends Bas
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.SHOULD, 3);
query.add(new Term(FIELD_NAME, "this"));//stop-word
query.add(new Term(FIELD_NAME, "long"));
Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java Tue Sep 8 12:16:06 2015
@@ -22,6 +22,7 @@ import org.apache.lucene.analysis.MockTo
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.index.IndexReader;
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.search.highlight.Highlighter;
@@ -114,8 +115,14 @@ public class HighlightCustomQueryTest ex
@Override
protected void extractUnknownQuery(Query query,
Map<String, WeightedSpanTerm> terms) throws IOException {
+ float boost = 1f;
+ while (query instanceof BoostQuery) {
+ BoostQuery bq = (BoostQuery) query;
+ boost *= bq.getBoost();
+ query = bq.getQuery();
+ }
if (query instanceof CustomQuery) {
- extractWeightedTerms(terms, new TermQuery(((CustomQuery) query).term));
+ extractWeightedTerms(terms, new TermQuery(((CustomQuery) query).term), boost);
}
}
Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java Tue Sep 8 12:16:06 2015
@@ -36,6 +36,7 @@ import org.apache.lucene.index.IndexWrit
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
@@ -113,7 +114,9 @@ public abstract class AbstractTestCase e
protected Query tq( float boost, String field, String text ){
Query query = new TermQuery( new Term( field, text ) );
- query.setBoost( boost );
+ if (boost != 1f) {
+ query = new BoostQuery( query, boost );
+ }
return query;
}
@@ -138,8 +141,10 @@ public abstract class AbstractTestCase e
}
protected Query pq( float boost, int slop, String field, String... texts ){
- PhraseQuery query = new PhraseQuery(slop, field, texts);
- query.setBoost( boost );
+ Query query = new PhraseQuery(slop, field, texts);
+ if (boost != 1f) {
+ query = new BoostQuery(query, boost);
+ }
return query;
}
Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java Tue Sep 8 12:16:06 2015
@@ -42,6 +42,7 @@ import org.apache.lucene.queries.CustomS
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.PhraseQuery;
import org.apache.lucene.search.Query;
@@ -305,7 +306,7 @@ public class FastVectorHighlighterTest e
BooleanQuery.Builder phraseB = new BooleanQuery.Builder();
phraseB.add( clause( "text", "highlight", "words", "together" ), Occur.MUST );
Query phrase = phraseB.build();
- phrase.setBoost( 100 );
+ phrase = new BoostQuery(phrase, 100f);
// Now combine those results in a boolean query which should pull the phrases to the front of the list of fragments
BooleanQuery.Builder query = new BooleanQuery.Builder();
query.add( phrase, Occur.MUST );
@@ -733,7 +734,7 @@ public class FastVectorHighlighterTest e
} else {
q = new PhraseQuery(field, terms);
}
- q.setBoost( boost );
+ q = new BoostQuery( q, boost );
return q;
}
Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FieldQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FieldQueryTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FieldQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FieldQueryTest.java Tue Sep 8 12:16:06 2015
@@ -27,6 +27,7 @@ import org.apache.lucene.index.LeafReade
import org.apache.lucene.index.Term;
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.DocIdSet;
import org.apache.lucene.search.Filter;
@@ -64,22 +65,22 @@ public class FieldQueryTest extends Abst
innerQuery.add(tq("E"), Occur.MUST);
booleanQueryB.add(innerQuery.build(), Occur.MUST_NOT);
- BooleanQuery booleanQuery = booleanQueryB.build();
- booleanQuery.setBoost(boost);
+ Query booleanQuery = booleanQueryB.build();
+ booleanQuery = new BoostQuery(booleanQuery, boost);
FieldQuery fq = new FieldQuery(booleanQuery, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten(booleanQuery, reader, flatQueries);
+ fq.flatten(booleanQuery, reader, flatQueries, 1f);
assertCollectionQueries( flatQueries, tq( boost, "A" ), tq( boost, "B" ), tq( boost, "C" ) );
}
public void testFlattenDisjunctionMaxQuery() throws Exception {
initBoost();
Query query = dmq( tq( "A" ), tq( "B" ), pqF( "C", "D" ) );
- query.setBoost( boost );
+ query = new BoostQuery( query, boost );
FieldQuery fq = new FieldQuery( query, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten( query, reader, flatQueries );
+ fq.flatten( query, reader, flatQueries, 1f );
assertCollectionQueries( flatQueries, tq( boost, "A" ), tq( boost, "B" ), pqF( boost, "C", "D" ) );
}
@@ -88,12 +89,12 @@ public class FieldQueryTest extends Abst
BooleanQuery.Builder booleanQueryB = new BooleanQuery.Builder();
booleanQueryB.add(tq("A"), Occur.MUST);
booleanQueryB.add(pqF("B", "C"), Occur.MUST);
- BooleanQuery booleanQuery = booleanQueryB.build();
- booleanQuery.setBoost(boost);
+ Query booleanQuery = booleanQueryB.build();
+ booleanQuery = new BoostQuery(booleanQuery, boost);
FieldQuery fq = new FieldQuery(booleanQuery, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten(booleanQuery, reader, flatQueries);
+ fq.flatten(booleanQuery, reader, flatQueries, 1f);
assertCollectionQueries( flatQueries, tq( boost, "A" ), pqF( boost, "B", "C" ) );
}
@@ -105,7 +106,7 @@ public class FieldQueryTest extends Abst
FieldQuery fq = new FieldQuery( query.build(), true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten( query.build(), reader, flatQueries );
+ fq.flatten( query.build(), reader, flatQueries, 1f );
assertCollectionQueries( flatQueries, tq( "AA" ), pqF( "BC", "CD" ), pqF( "EF", "FG", "GH" ) );
}
@@ -113,7 +114,7 @@ public class FieldQueryTest extends Abst
Query query = pqF( "A" );
FieldQuery fq = new FieldQuery( query, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten( query, reader, flatQueries );
+ fq.flatten( query, reader, flatQueries, 1f );
assertCollectionQueries( flatQueries, tq( "A" ) );
}
@@ -951,20 +952,20 @@ public class FieldQueryTest extends Abst
return "filterToBeFlattened";
}
});
- query.setBoost(boost);
+ query = new BoostQuery(query, boost);
FieldQuery fq = new FieldQuery( query, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten( query, reader, flatQueries );
+ fq.flatten( query, reader, flatQueries, 1f );
assertCollectionQueries( flatQueries, tq( boost, "A" ) );
}
public void testFlattenConstantScoreQuery() throws Exception {
initBoost();
Query query = new ConstantScoreQuery(pqF( "A" ));
- query.setBoost(boost);
+ query = new BoostQuery(query, boost);
FieldQuery fq = new FieldQuery( query, true, true );
Set<Query> flatQueries = new HashSet<>();
- fq.flatten( query, reader, flatQueries );
+ fq.flatten( query, reader, flatQueries, 1f );
assertCollectionQueries( flatQueries, tq( boost, "A" ) );
}
Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java Tue Sep 8 12:16:06 2015
@@ -26,6 +26,7 @@ import org.apache.lucene.index.LeafReade
import org.apache.lucene.index.MultiDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
@@ -97,13 +98,10 @@ final class GlobalOrdinalsQuery extends
'}';
}
- final class W extends Weight {
+ final class W extends ConstantScoreWeight {
private final Weight approximationWeight;
- private float queryNorm;
- private float queryWeight;
-
W(Query query, Weight approximationWeight) {
super(query);
this.approximationWeight = approximationWeight;
@@ -119,25 +117,13 @@ final class GlobalOrdinalsQuery extends
int segmentOrd = values.getOrd(doc);
if (segmentOrd != -1) {
BytesRef joinValue = values.lookupOrd(segmentOrd);
- return Explanation.match(queryNorm, "Score based on join value " + joinValue.utf8ToString());
+ return Explanation.match(score(), "Score based on join value " + joinValue.utf8ToString());
}
}
return Explanation.noMatch("Not a match");
}
@Override
- public float getValueForNormalization() throws IOException {
- queryWeight = getBoost();
- return queryWeight * queryWeight;
- }
-
- @Override
- public void normalize(float norm, float topLevelBoost) {
- this.queryNorm = norm * topLevelBoost;
- queryWeight *= this.queryNorm;
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
if (values == null) {
@@ -149,9 +135,9 @@ final class GlobalOrdinalsQuery extends
return null;
}
if (globalOrds != null) {
- return new OrdinalMapScorer(this, queryNorm, foundOrds, values, approximationScorer, globalOrds.getGlobalOrds(context.ord));
+ return new OrdinalMapScorer(this, score(), foundOrds, values, approximationScorer, globalOrds.getGlobalOrds(context.ord));
} {
- return new SegmentOrdinalScorer(this, queryNorm, foundOrds, values, approximationScorer);
+ return new SegmentOrdinalScorer(this, score(), foundOrds, values, approximationScorer);
}
}
Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java Tue Sep 8 12:16:06 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;
@@ -76,14 +75,15 @@ class TermsIncludingScoreQuery extends Q
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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 +146,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/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java Tue Sep 8 12:16:06 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
@@ -315,15 +313,16 @@ public class ToChildBlockJoinQuery exten
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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 +351,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/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java Tue Sep 8 12:16:06 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
@@ -411,16 +411,17 @@ public class ToParentBlockJoinQuery exte
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java Tue Sep 8 12:16:06 2015
@@ -48,6 +48,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;
@@ -420,8 +421,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/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/index/SorterTestBase.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java Tue Sep 8 12:16:06 2015
@@ -422,9 +422,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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java Tue Sep 8 12:16:06 2015
@@ -49,19 +49,19 @@ 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
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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 +101,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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java Tue Sep 8 12:16:06 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
@@ -145,12 +145,13 @@ public class CommonTermsQuery extends Qu
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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 +227,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 +237,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 +344,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 +364,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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java Tue Sep 8 12:16:06 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).
@@ -88,6 +86,9 @@ public class CustomScoreQuery extends Qu
/*(non-Javadoc) @see org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader) */
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
CustomScoreQuery clone = null;
final Query sq = subQuery.rewrite(reader);
@@ -110,11 +111,11 @@ 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 = (CustomScoreQuery) super.clone();
+ 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 +130,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 +140,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;
@@ -155,8 +152,8 @@ public class CustomScoreQuery extends Qu
/** Returns a hash code value for this object. */
@Override
public int hashCode() {
- return (getClass().hashCode() + subQuery.hashCode() + Arrays.hashCode(scoringQueries))
- ^ Float.floatToIntBits(getBoost()) ^ (strict ? 1234 : 4321);
+ return (super.hashCode() + subQuery.hashCode() + Arrays.hashCode(scoringQueries))
+ ^ (strict ? 1234 : 4321);
}
/**
@@ -199,9 +196,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 +205,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 +219,7 @@ public class CustomScoreQuery extends Qu
valSrcWeight.normalize(norm, 1f);
}
}
- queryWeight = topLevelBoost * getBoost();
+ queryWeight = boost;
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java Tue Sep 8 12:16:06 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
@@ -142,6 +141,9 @@ public class TermsQuery extends Query im
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount());
if (termData.size() <= threshold) {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
@@ -149,9 +151,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 +188,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 +308,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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java Tue Sep 8 12:16:06 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) {
@@ -53,11 +53,14 @@ public class BoostedQuery extends Query
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
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 +69,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 +86,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 +100,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 +118,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 +160,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 +173,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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java Tue Sep 8 12:16:06 2015
@@ -60,6 +60,9 @@ public class MoreLikeThisQuery extends Q
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
MoreLikeThis mlt = new MoreLikeThis(reader);
mlt.setFieldNames(moreLikeFields);
@@ -78,9 +81,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/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java Tue Sep 8 12:16:06 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
Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java Tue Sep 8 12:16:06 2015
@@ -30,11 +30,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;
@@ -251,6 +253,9 @@ public class ComplexPhraseQueryParser ex
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
final Query contents = this.contents[0];
// ArrayList spanClauses = new ArrayList();
if (contents instanceof TermQuery) {
@@ -279,6 +284,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);
@@ -348,6 +357,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) {
@@ -356,8 +372,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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BoostQueryNodeBuilder.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/SlopQueryNodeBuilder.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceQuery.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/DistanceRewriteQuery.java Tue Sep 8 12:16:06 2015
@@ -32,7 +32,10 @@ class DistanceRewriteQuery extends Rewri
@Override
public Query rewrite(IndexReader reader) throws IOException {
- return srndQuery.getSpanNearQuery(reader, fieldName, getBoost(), qf);
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
+ return srndQuery.getSpanNearQuery(reader, fieldName, qf);
}
}
Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java Tue Sep 8 12:16:06 2015
@@ -15,9 +15,7 @@ package org.apache.lucene.queryparser.su
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import java.io.IOException;
-import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
abstract class RewriteQuery<SQ extends SrndQuery> extends Query {
@@ -35,9 +33,6 @@ abstract class RewriteQuery<SQ extends S
}
@Override
- abstract public Query rewrite(IndexReader reader) throws IOException;
-
- @Override
public String toString(String field) {
return getClass().getName()
+ (field.isEmpty() ? "" : "(unused: " + field + ")")
Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SimpleTermRewriteQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SimpleTermRewriteQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SimpleTermRewriteQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SimpleTermRewriteQuery.java Tue Sep 8 12:16:06 2015
@@ -36,6 +36,9 @@ class SimpleTermRewriteQuery extends Rew
@Override
public Query rewrite(IndexReader reader) throws IOException {
+ if (getBoost() != 1f) {
+ return super.rewrite(reader);
+ }
final List<Query> luceneSubQueries = new ArrayList<>();
srndQuery.visitMatchingTerms(reader, fieldName,
new SimpleTerm.MatchingTermVisitor() {
Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SpanNearClauseFactory.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/SrndQuery.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingQueryBuilder.java Tue Sep 8 12:16:06 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/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BoostingTermBuilder.java Tue Sep 8 12:16:06 2015
@@ -1,11 +1,12 @@
package org.apache.lucene.queryparser.xml.builders;
import org.apache.lucene.index.Term;
+import org.apache.lucene.queryparser.xml.DOMUtils;
+import org.apache.lucene.queryparser.xml.ParserException;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadTermQuery;
+import org.apache.lucene.search.spans.SpanBoostQuery;
import org.apache.lucene.search.spans.SpanQuery;
-import org.apache.lucene.queryparser.xml.DOMUtils;
-import org.apache.lucene.queryparser.xml.ParserException;
import org.w3c.dom.Element;
/*
@@ -35,8 +36,8 @@ public class BoostingTermBuilder extends
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
- PayloadTermQuery btq = new PayloadTermQuery(new Term(fieldName, value), new AveragePayloadFunction());
- btq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
+ SpanQuery btq = new PayloadTermQuery(new Term(fieldName, value), new AveragePayloadFunction());
+ btq = new SpanBoostQuery(btq, DOMUtils.getAttribute(e, "boost", 1.0f));
return btq;
}