mirror of https://github.com/apache/lucene.git
reformat spacing
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b058f63c30
commit
798fc0f0ef
|
@ -60,87 +60,89 @@ import org.apache.lucene.util.*;
|
|||
import org.apache.lucene.index.*;
|
||||
|
||||
abstract class PhraseScorer extends Scorer {
|
||||
private Weight weight;
|
||||
protected byte[] norms;
|
||||
protected float value;
|
||||
private Weight weight;
|
||||
protected byte[] norms;
|
||||
protected float value;
|
||||
|
||||
protected PhraseQueue pq;
|
||||
protected PhrasePositions first, last;
|
||||
protected PhraseQueue pq;
|
||||
protected PhrasePositions first, last;
|
||||
|
||||
private float freq;
|
||||
private float freq;
|
||||
|
||||
PhraseScorer(Weight weight, TermPositions[] tps, Similarity similarity,
|
||||
byte[] norms) throws IOException {
|
||||
super(similarity);
|
||||
this.norms = norms;
|
||||
this.weight = weight;
|
||||
this.value = weight.getValue();
|
||||
PhraseScorer(Weight weight, TermPositions[] tps, Similarity similarity,
|
||||
byte[] norms) throws IOException {
|
||||
super(similarity);
|
||||
this.norms = norms;
|
||||
this.weight = weight;
|
||||
this.value = weight.getValue();
|
||||
|
||||
// use PQ to build a sorted list of PhrasePositions
|
||||
pq = new PhraseQueue(tps.length);
|
||||
for (int i = 0; i < tps.length; i++)
|
||||
pq.put(new PhrasePositions(tps[i], i));
|
||||
pqToList();
|
||||
}
|
||||
|
||||
public final void score(HitCollector results, int end) throws IOException {
|
||||
Similarity similarity = getSimilarity();
|
||||
while (last.doc < end) { // find doc w/ all the terms
|
||||
while (first.doc < last.doc) { // scan forward in first
|
||||
do {
|
||||
first.next();
|
||||
} while (first.doc < last.doc);
|
||||
firstToLast();
|
||||
if (last.doc >= end)
|
||||
return;
|
||||
}
|
||||
|
||||
// found doc with all terms
|
||||
freq = phraseFreq(); // check for phrase
|
||||
|
||||
if (freq > 0.0) {
|
||||
float score = similarity.tf(freq)*value; // compute score
|
||||
score *= Similarity.decodeNorm(norms[first.doc]); // normalize
|
||||
results.collect(first.doc, score); // add to results
|
||||
}
|
||||
last.next(); // resume scanning
|
||||
// use PQ to build a sorted list of PhrasePositions
|
||||
pq = new PhraseQueue(tps.length);
|
||||
for (int i = 0; i < tps.length; i++) {
|
||||
pq.put(new PhrasePositions(tps[i], i));
|
||||
}
|
||||
pqToList();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract float phraseFreq() throws IOException;
|
||||
public final void score(HitCollector results, int end) throws IOException {
|
||||
Similarity similarity = getSimilarity();
|
||||
while (last.doc < end) { // find doc w/ all the terms
|
||||
while (first.doc < last.doc) { // scan forward in first
|
||||
do {
|
||||
first.next();
|
||||
} while (first.doc < last.doc);
|
||||
firstToLast();
|
||||
if (last.doc >= end)
|
||||
return;
|
||||
}
|
||||
|
||||
protected final void pqToList() {
|
||||
last = first = null;
|
||||
while (pq.top() != null) {
|
||||
PhrasePositions pp = (PhrasePositions)pq.pop();
|
||||
if (last != null) { // add next to end of list
|
||||
last.next = pp;
|
||||
} else
|
||||
first = pp;
|
||||
last = pp;
|
||||
pp.next = null;
|
||||
// found doc with all terms
|
||||
freq = phraseFreq(); // check for phrase
|
||||
|
||||
if (freq > 0.0) {
|
||||
float score = similarity.tf(freq) * value; // compute score
|
||||
score *= Similarity.decodeNorm(norms[first.doc]); // normalize
|
||||
results.collect(first.doc, score); // add to results
|
||||
}
|
||||
last.next(); // resume scanning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void firstToLast() {
|
||||
last.next = first; // move first to end of list
|
||||
last = first;
|
||||
first = first.next;
|
||||
last.next = null;
|
||||
}
|
||||
protected abstract float phraseFreq() throws IOException;
|
||||
|
||||
public Explanation explain(final int doc) throws IOException {
|
||||
Explanation tfExplanation = new Explanation();
|
||||
protected final void pqToList() {
|
||||
last = first = null;
|
||||
while (pq.top() != null) {
|
||||
PhrasePositions pp = (PhrasePositions) pq.pop();
|
||||
if (last != null) { // add next to end of list
|
||||
last.next = pp;
|
||||
} else
|
||||
first = pp;
|
||||
last = pp;
|
||||
pp.next = null;
|
||||
}
|
||||
}
|
||||
|
||||
score(new HitCollector() {
|
||||
public final void collect(int d, float score) {}
|
||||
}, doc+1);
|
||||
protected final void firstToLast() {
|
||||
last.next = first; // move first to end of list
|
||||
last = first;
|
||||
first = first.next;
|
||||
last.next = null;
|
||||
}
|
||||
|
||||
float phraseFreq = (first.doc == doc) ? freq : 0.0f;
|
||||
tfExplanation.setValue(getSimilarity().tf(phraseFreq));
|
||||
tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");
|
||||
public Explanation explain(final int doc) throws IOException {
|
||||
Explanation tfExplanation = new Explanation();
|
||||
|
||||
return tfExplanation;
|
||||
}
|
||||
score(new HitCollector() {
|
||||
public final void collect(int d, float score) {
|
||||
}
|
||||
}, doc + 1);
|
||||
|
||||
float phraseFreq = (first.doc == doc) ? freq : 0.0f;
|
||||
tfExplanation.setValue(getSimilarity().tf(phraseFreq));
|
||||
tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");
|
||||
|
||||
return tfExplanation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,53 +54,52 @@ package org.apache.lucene.search;
|
|||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.TermPositions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.util.*;
|
||||
import org.apache.lucene.index.*;
|
||||
|
||||
final class SloppyPhraseScorer extends PhraseScorer {
|
||||
private int slop;
|
||||
private int slop;
|
||||
|
||||
SloppyPhraseScorer(Weight weight, TermPositions[] tps, Similarity similarity,
|
||||
int slop, byte[] norms) throws IOException {
|
||||
super(weight, tps, similarity, norms);
|
||||
this.slop = slop;
|
||||
}
|
||||
|
||||
protected final float phraseFreq() throws IOException {
|
||||
pq.clear();
|
||||
int end = 0;
|
||||
for (PhrasePositions pp = first; pp != null; pp = pp.next) {
|
||||
pp.firstPosition();
|
||||
if (pp.position > end)
|
||||
end = pp.position;
|
||||
pq.put(pp); // build pq from list
|
||||
SloppyPhraseScorer(Weight weight, TermPositions[] tps, Similarity similarity,
|
||||
int slop, byte[] norms) throws IOException {
|
||||
super(weight, tps, similarity, norms);
|
||||
this.slop = slop;
|
||||
}
|
||||
|
||||
float freq = 0.0f;
|
||||
boolean done = false;
|
||||
do {
|
||||
PhrasePositions pp = (PhrasePositions)pq.pop();
|
||||
int start = pp.position;
|
||||
int next = ((PhrasePositions)pq.top()).position;
|
||||
for (int pos = start; pos <= next; pos = pp.position) {
|
||||
start = pos; // advance pp to min window
|
||||
if (!pp.nextPosition()) {
|
||||
done = true; // ran out of a term -- done
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected final float phraseFreq() throws IOException {
|
||||
pq.clear();
|
||||
int end = 0;
|
||||
for (PhrasePositions pp = first; pp != null; pp = pp.next) {
|
||||
pp.firstPosition();
|
||||
if (pp.position > end)
|
||||
end = pp.position;
|
||||
pq.put(pp); // build pq from list
|
||||
}
|
||||
|
||||
int matchLength = end - start;
|
||||
if (matchLength <= slop)
|
||||
freq += getSimilarity().sloppyFreq(matchLength); // score match
|
||||
float freq = 0.0f;
|
||||
boolean done = false;
|
||||
do {
|
||||
PhrasePositions pp = (PhrasePositions) pq.pop();
|
||||
int start = pp.position;
|
||||
int next = ((PhrasePositions) pq.top()).position;
|
||||
for (int pos = start; pos <= next; pos = pp.position) {
|
||||
start = pos; // advance pp to min window
|
||||
if (!pp.nextPosition()) {
|
||||
done = true; // ran out of a term -- done
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pp.position > end)
|
||||
end = pp.position;
|
||||
pq.put(pp); // restore pq
|
||||
} while (!done);
|
||||
|
||||
return freq;
|
||||
}
|
||||
int matchLength = end - start;
|
||||
if (matchLength <= slop)
|
||||
freq += getSimilarity().sloppyFreq(matchLength); // score match
|
||||
|
||||
if (pp.position > end)
|
||||
end = pp.position;
|
||||
pq.put(pp); // restore pq
|
||||
} while (!done);
|
||||
|
||||
return freq;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue