Fixed a bug with explain().

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2003-01-14 19:20:30 +00:00
parent bc3aa553d5
commit a2042c190b
4 changed files with 21 additions and 29 deletions

View File

@ -141,6 +141,10 @@ $Id$
fairly advanced programming, and I don't expect anyone to do
this anytime soon, but at least now it is possible.
g. Added public accessors to the primitive query classes
(TermQuery, PhraseQuery and BooleanQuery), permitting access to
their terms and clauses.
Caution: These are extensive changes and they have not yet been
tested extensively. Bug reports are appreciated.
(cutting)

View File

@ -135,13 +135,6 @@ public class BooleanQuery extends Query {
}
public Scorer scorer(IndexReader reader) throws IOException {
if (weights.size() == 1) { // optimize 1-clause queries
BooleanClause c = (BooleanClause)clauses.elementAt(0);
Weight w = (Weight)weights.elementAt(0);
if (!c.prohibited) // just return clause scorer
return w.scorer(reader);
}
BooleanScorer result = new BooleanScorer(searcher.getSimilarity());
for (int i = 0 ; i < weights.size(); i++) {
@ -167,6 +160,11 @@ public class BooleanQuery extends Query {
}
protected Weight createWeight(Searcher searcher) {
if (clauses.size() == 1) { // optimize 1-clause queries
BooleanClause c = (BooleanClause)clauses.elementAt(0);
if (!c.prohibited) // just return clause weight
return c.query.createWeight(searcher);
}
return new BooleanWeight(searcher);
}

View File

@ -155,20 +155,6 @@ public class PhrasePrefixQuery extends Query {
if (termArrays.size() == 0) // optimize zero-term case
return null;
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanScorer bos = new BooleanScorer(searcher.getSimilarity());
for (int i=0; i<terms.length; i++) {
TermDocs docs = reader.termDocs(terms[i]);
if (docs != null)
bos.add(new TermScorer(this, docs, searcher.getSimilarity(),
reader.norms(field)), false, false);
}
return bos;
}
TermPositions[] tps = new TermPositions[termArrays.size()];
for (int i=0; i<tps.length; i++) {
Term[] terms = (Term[])termArrays.get(i);
@ -218,6 +204,14 @@ public class PhrasePrefixQuery extends Query {
}
protected Weight createWeight(Searcher searcher) {
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanQuery boq = new BooleanQuery();
for (int i=0; i<terms.length; i++) {
boq.add(new TermQuery(terms[i]), false, false);
}
return boq.createWeight(searcher);
}
return new PhrasePrefixWeight(searcher);
}

View File

@ -135,14 +135,6 @@ public class PhraseQuery extends Query {
public Scorer scorer(IndexReader reader) throws IOException {
if (terms.size() == 0) // optimize zero-term case
return null;
if (terms.size() == 1) { // optimize one-term case
Term term = (Term)terms.elementAt(0);
TermDocs docs = reader.termDocs(term);
if (docs == null)
return null;
return new TermScorer(this, docs, searcher.getSimilarity(),
reader.norms(term.field()));
}
TermPositions[] tps = new TermPositions[terms.size()];
for (int i = 0; i < terms.size(); i++) {
@ -195,6 +187,10 @@ public class PhraseQuery extends Query {
}
protected Weight createWeight(Searcher searcher) {
if (terms.size() == 1) { // optimize one-term case
Term term = (Term)terms.elementAt(0);
return new TermQuery(term).createWeight(searcher);
}
return new PhraseWeight(searcher);
}