Skip to content

Commit

Permalink
Query: match_all query (also in query_string: *:*) is very slow, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Oct 26, 2010
1 parent 36e31de commit a78d4d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 70 deletions.
Expand Up @@ -66,15 +66,15 @@ private AllDocIdSetIterator(int maxDoc) {
if (++doc < maxDoc) {
return doc;
}
return NO_MORE_DOCS;
return doc = NO_MORE_DOCS;
}

@Override public int advance(int target) throws IOException {
doc = target;
if (doc < maxDoc) {
return doc;
}
return NO_MORE_DOCS;
return doc = NO_MORE_DOCS;
}
}
}
Expand Up @@ -19,90 +19,26 @@

package org.elasticsearch.common.lucene.docset;

import org.apache.lucene.search.DocIdSetIterator;

import java.io.IOException;

/**
* @author kimchy (shay.banon)
*/
public class NotDocSet extends DocSet {
public class NotDocSet extends GetDocSet {

private final DocSet set;

private final int max;

public NotDocSet(DocSet set, int max) {
super(max);
this.set = set;
this.max = max;
}

@Override public boolean isCacheable() {
return set.isCacheable();
// if it is cached, create a new doc set for it so it will be fast for advance in iterator
return false;
}

@Override public boolean get(int doc) throws IOException {
return !set.get(doc);
}

@Override public DocIdSetIterator iterator() throws IOException {
return new NotDocIdSetIterator();
}

class NotDocIdSetIterator extends DocIdSetIterator {
int lastReturn = -1;
private DocIdSetIterator it1 = null;
private int innerDocid = -1;

NotDocIdSetIterator() throws IOException {
initialize();
}

private void initialize() throws IOException {
it1 = set.iterator();

try {
if ((innerDocid = it1.nextDoc()) == DocIdSetIterator.NO_MORE_DOCS) it1 = null;
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public int docID() {
return lastReturn;
}

@Override
public int nextDoc() throws IOException {
return advance(0);
}

@Override
public int advance(int target) throws IOException {

if (lastReturn == DocIdSetIterator.NO_MORE_DOCS) {
return DocIdSetIterator.NO_MORE_DOCS;
}

if (target <= lastReturn) target = lastReturn + 1;

if (it1 != null && innerDocid < target) {
if ((innerDocid = it1.advance(target)) == DocIdSetIterator.NO_MORE_DOCS) {
it1 = null;
}
}

while (it1 != null && innerDocid == target) {
target++;
if (target >= max) {
return (lastReturn = DocIdSetIterator.NO_MORE_DOCS);
}
if ((innerDocid = it1.advance(target)) == DocIdSetIterator.NO_MORE_DOCS) {
it1 = null;
}
}
return (lastReturn = target);
}
}
}

0 comments on commit a78d4d9

Please sign in to comment.