New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to lucene-5.2.0-snapshot-1673124. #10562
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,12 @@ | |
import org.apache.lucene.search.ComplexExplanation; | ||
import org.apache.lucene.search.Explanation; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.search.Weight; | ||
import org.apache.lucene.search.similarities.Similarity; | ||
import org.apache.lucene.search.similarities.Similarity.SimScorer; | ||
import org.apache.lucene.search.spans.SpanScorer; | ||
import org.apache.lucene.search.spans.SpanTermQuery; | ||
import org.apache.lucene.search.spans.SpanWeight; | ||
import org.apache.lucene.search.spans.Spans; | ||
import org.apache.lucene.search.spans.TermSpans; | ||
import org.apache.lucene.util.Bits; | ||
import org.apache.lucene.util.BytesRef; | ||
|
@@ -51,7 +51,7 @@ public AllTermQuery(Term term) { | |
} | ||
|
||
@Override | ||
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { | ||
public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { | ||
// TODO: needsScores | ||
// we should be able to just return a regular SpanTermWeight, at most here if needsScores == false? | ||
return new AllTermWeight(this, searcher); | ||
|
@@ -68,40 +68,56 @@ public AllTermSpanScorer scorer(LeafReaderContext context, Bits acceptDocs) thro | |
if (this.stats == null) { | ||
return null; | ||
} | ||
TermSpans spans = (TermSpans) query.getSpans(context, acceptDocs, termContexts); | ||
if (spans == null) { | ||
return null; | ||
} | ||
SimScorer sloppySimScorer = similarity.simScorer(stats, context); | ||
return new AllTermSpanScorer((TermSpans) query.getSpans(context, acceptDocs, termContexts), this, sloppySimScorer); | ||
return new AllTermSpanScorer(spans, this, sloppySimScorer); | ||
} | ||
|
||
protected class AllTermSpanScorer extends SpanScorer { | ||
protected PostingsEnum positions; | ||
protected float payloadScore; | ||
protected int payloadsSeen; | ||
|
||
public AllTermSpanScorer(TermSpans spans, Weight weight, Similarity.SimScorer docScorer) throws IOException { | ||
public AllTermSpanScorer(TermSpans spans, SpanWeight weight, Similarity.SimScorer docScorer) throws IOException { | ||
super(spans, weight, docScorer); | ||
positions = spans.getPostings(); | ||
} | ||
|
||
@Override | ||
protected boolean setFreqCurrentDoc() throws IOException { | ||
if (!more) { | ||
return false; | ||
} | ||
doc = spans.doc(); | ||
protected void setFreqCurrentDoc() throws IOException { | ||
freq = 0.0f; | ||
numMatches = 0; | ||
payloadScore = 0; | ||
payloadsSeen = 0; | ||
do { | ||
int matchLength = spans.end() - spans.start(); | ||
|
||
freq += docScorer.computeSlopFactor(matchLength); | ||
assert spans.startPosition() == -1 : "incorrect initial start position, spans="+spans; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine for now, but note this stuff got excessive in all the spans and still would not find bugs. In order to make things debuggable i had to solve it another way: https://issues.apache.org/jira/browse/LUCENE-6411 So I am not sure about all the asserts, to me I just get lost in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not want to do anything smart, this just copies over logic from SpanScorer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the copy-paste at all? This whole thing seems like a code duplication of PayloadTermQuery. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And i just did not have the time to yet yesterday remove the stupid asserts from SpanScorer. Please, lets not drag this stuff in again. If oyu want to push fine, but you will see a second push from me removing all this crap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The duplication comes from the fact that AllTermScorer needs to process the payload in the middle of the setFreqCurrentDoc loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is just what PayloadTermQuery does, too. So again how is this different from PayloadTermScorer? Even the variable/method names are similar. |
||
assert spans.endPosition() == -1 : "incorrect initial end position, spans="+spans; | ||
int prevStartPos = -1; | ||
int prevEndPos = -1; | ||
|
||
int startPos = spans.nextStartPosition(); | ||
assert startPos != Spans.NO_MORE_POSITIONS : "initial startPos NO_MORE_POSITIONS, spans="+spans; | ||
do { | ||
assert startPos >= prevStartPos; | ||
int endPos = spans.endPosition(); | ||
assert endPos != Spans.NO_MORE_POSITIONS; | ||
// This assertion can fail for Or spans on the same term: | ||
// assert (startPos != prevStartPos) || (endPos > prevEndPos) : "non increased endPos="+endPos; | ||
assert (startPos != prevStartPos) || (endPos >= prevEndPos) : "decreased endPos="+endPos; | ||
numMatches++; | ||
int matchLength = endPos - startPos; | ||
freq += docScorer.computeSlopFactor(matchLength); | ||
processPayload(); | ||
prevStartPos = startPos; | ||
prevEndPos = endPos; | ||
startPos = spans.nextStartPosition(); | ||
} while (startPos != Spans.NO_MORE_POSITIONS); | ||
|
||
more = spans.next();// this moves positions to the next match | ||
} while (more && (doc == spans.doc())); | ||
return true; | ||
assert spans.startPosition() == Spans.NO_MORE_POSITIONS : "incorrect final start position, spans="+spans; | ||
assert spans.endPosition() == Spans.NO_MORE_POSITIONS : "incorrect final end position, spans="+spans; | ||
} | ||
|
||
protected void processPayload() throws IOException { | ||
|
@@ -120,7 +136,7 @@ protected void processPayload() throws IOException { | |
* @throws IOException | ||
*/ | ||
@Override | ||
public float score() throws IOException { | ||
public float scoreCurrentDoc() throws IOException { | ||
return getSpanScore() * getPayloadScore(); | ||
} | ||
|
||
|
@@ -134,7 +150,7 @@ public float score() throws IOException { | |
* @see #score() | ||
*/ | ||
protected float getSpanScore() throws IOException { | ||
return super.score(); | ||
return super.scoreCurrentDoc(); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class overrides weight/scorer, where is its positions check (throw IAE if proximity is not enabled) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to fix it in Lucene too then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you are a bit behind. I added tests for this position check last night and fixed bugs in the default impl.