mirror of https://github.com/apache/lucene.git
LUCENE-7259: speed up MatchingPoints cost estimation
This commit is contained in:
parent
3b4ec73595
commit
ebd120465a
|
@ -108,6 +108,11 @@ abstract class LatLonPointBoxQuery extends Query {
|
||||||
values.intersect(field,
|
values.intersect(field,
|
||||||
new IntersectVisitor() {
|
new IntersectVisitor() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void grow(int count) {
|
||||||
|
result.grow(count);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(int docID) {
|
public void visit(int docID) {
|
||||||
result.add(docID);
|
result.add(docID);
|
||||||
|
|
|
@ -121,6 +121,11 @@ final class LatLonPointDistanceQuery extends Query {
|
||||||
|
|
||||||
values.intersect(field,
|
values.intersect(field,
|
||||||
new IntersectVisitor() {
|
new IntersectVisitor() {
|
||||||
|
@Override
|
||||||
|
public void grow(int count) {
|
||||||
|
result.grow(count);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(int docID) {
|
public void visit(int docID) {
|
||||||
result.add(docID);
|
result.add(docID);
|
||||||
|
|
|
@ -114,6 +114,11 @@ final class LatLonPointInPolygonQuery extends Query {
|
||||||
|
|
||||||
values.intersect(field,
|
values.intersect(field,
|
||||||
new IntersectVisitor() {
|
new IntersectVisitor() {
|
||||||
|
@Override
|
||||||
|
public void grow(int count) {
|
||||||
|
result.grow(count);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(int docID) {
|
public void visit(int docID) {
|
||||||
result.add(docID);
|
result.add(docID);
|
||||||
|
|
|
@ -30,6 +30,9 @@ import org.apache.lucene.util.SparseFixedBitSet;
|
||||||
* Add matches with ({@link #add(int)}) and call {@link #iterator()} for
|
* Add matches with ({@link #add(int)}) and call {@link #iterator()} for
|
||||||
* an iterator over the results.
|
* an iterator over the results.
|
||||||
* <p>
|
* <p>
|
||||||
|
* <b>NOTE:</b> it is required that you implement the optional {@code grow()}
|
||||||
|
* method in your IntersectVisitor, this is used for cost computation.
|
||||||
|
* <p>
|
||||||
* This implementation currently optimizes bitset structure (sparse vs dense)
|
* This implementation currently optimizes bitset structure (sparse vs dense)
|
||||||
* and {@link DocIdSetIterator#cost()} (cardinality) based on index statistics.
|
* and {@link DocIdSetIterator#cost()} (cardinality) based on index statistics.
|
||||||
* This API may change as point values evolves.
|
* This API may change as point values evolves.
|
||||||
|
@ -76,15 +79,24 @@ final class MatchingPoints {
|
||||||
*/
|
*/
|
||||||
public void add(int doc) {
|
public void add(int doc) {
|
||||||
bits.set(doc);
|
bits.set(doc);
|
||||||
counter++;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grows cardinality counter by the given amount.
|
||||||
|
*/
|
||||||
|
public void grow(int amount) {
|
||||||
|
counter += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator over the recorded matches.
|
* Returns an iterator over the recorded matches.
|
||||||
*/
|
*/
|
||||||
public DocIdSetIterator iterator() {
|
public DocIdSetIterator iterator() {
|
||||||
// if single-valued (docCount == numPoints), then this is exact
|
// ensure caller implements the grow() api
|
||||||
// otherwise its approximate based on field stats
|
assert counter > 0 || bits.cardinality() == 0 : "the IntersectVisitor is missing grow()";
|
||||||
|
|
||||||
|
// if single-valued (docCount == numPoints), then we know 1 point == 1 doc
|
||||||
|
// otherwise we approximate based on field stats
|
||||||
return new BitSetIterator(bits, (long) (counter * (docCount / (double) numPoints)));
|
return new BitSetIterator(bits, (long) (counter * (docCount / (double) numPoints)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue