FileDocCategorySizeDatePackage
TestExplanations.javaAPI DocApache Lucene 2.1.07726Wed Feb 14 10:46:36 GMT 2007org.apache.lucene.search

TestExplanations

public class TestExplanations extends TestCase
Tests primative queries (ie: that rewrite to themselves) to insure they match the expected set of docs, and that the score of each match is equal to the value of the scores explanation.

The assumption is that if all of the "primative" queries work well, then anythingthat rewrites to a primative will work well also.

see
"Subclasses for actual tests"

Fields Summary
protected IndexSearcher
searcher
public static final String
FIELD
public static final QueryParser
qp
protected String[]
docFields
Constructors Summary
Methods Summary
public voidbqtest(org.apache.lucene.search.Query q, int[] expDocNrs)
Tests a query using qtest after wrapping it with both optB and reqB

see
#qtest
see
#reqB
see
#optB

    qtest(reqB(q), expDocNrs);
    qtest(optB(q), expDocNrs);
  
public voidbqtest(java.lang.String queryText, int[] expDocNrs)
Tests a query using qtest after wrapping it with both optB and reqB

see
#qtest
see
#reqB
see
#optB

    bqtest(makeQuery(queryText), expDocNrs);
  
public org.apache.lucene.search.QuerymakeQuery(java.lang.String queryText)


        
    return qp.parse(queryText);
  
public org.apache.lucene.search.QueryoptB(java.lang.String q)
MACRO: Wraps a Query in a BooleanQuery so that it is optional, along with a second prohibited clause which will never match anything

    return optB(makeQuery(q));
  
public org.apache.lucene.search.QueryoptB(org.apache.lucene.search.Query q)
MACRO: Wraps a Query in a BooleanQuery so that it is optional, along with a second prohibited clause which will never match anything

    BooleanQuery bq = new BooleanQuery(true);
    bq.add(q, BooleanClause.Occur.SHOULD);
    bq.add(new TermQuery(new Term("NEVER","MATCH")), BooleanClause.Occur.MUST_NOT);
    return bq;
  
public voidqtest(java.lang.String queryText, int[] expDocNrs)

    qtest(makeQuery(queryText), expDocNrs);
  
public voidqtest(org.apache.lucene.search.Query q, int[] expDocNrs)

    // check that the expDocNrs first, then check the explanations
    CheckHits.checkHitCollector(q, FIELD, searcher, expDocNrs);
    CheckHits.checkExplanations(q, FIELD, searcher);
  
public org.apache.lucene.search.QueryreqB(java.lang.String q)
MACRO: Wraps a Query in a BooleanQuery so that it is required, along with a second optional clause which will match everything

    return reqB(makeQuery(q));
  
public org.apache.lucene.search.QueryreqB(org.apache.lucene.search.Query q)
MACRO: Wraps a Query in a BooleanQuery so that it is required, along with a second optional clause which will match everything

    BooleanQuery bq = new BooleanQuery(true);
    bq.add(q, BooleanClause.Occur.MUST);
    bq.add(new TermQuery(new Term(FIELD,"w1")), BooleanClause.Occur.SHOULD);
    return bq;
  
public voidsetUp()

    RAMDirectory directory = new RAMDirectory();
    IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
    for (int i = 0; i < docFields.length; i++) {
      Document doc = new Document();
      doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
      writer.addDocument(doc);
    }
    writer.close();
    searcher = new IndexSearcher(directory);
  
public org.apache.lucene.search.spans.SpanFirstQuerysf(java.lang.String s, int b)
MACRO for SpanFirst(SpanTermQuery)

    return new SpanFirstQuery(st(s), b);
  
public org.apache.lucene.search.spans.SpanNearQuerysnear(java.lang.String s, java.lang.String e, int slop, boolean inOrder)
MACRO for SpanNearQuery containing two SpanTerm queries

    return snear(st(s), st(e), slop, inOrder);
  
public org.apache.lucene.search.spans.SpanNearQuerysnear(org.apache.lucene.search.spans.SpanQuery s, org.apache.lucene.search.spans.SpanQuery e, int slop, boolean inOrder)
MACRO for SpanNearQuery containing two SpanQueries

    return new SpanNearQuery(new SpanQuery[] { s, e }, slop, inOrder);
  
public org.apache.lucene.search.spans.SpanNearQuerysnear(java.lang.String s, java.lang.String m, java.lang.String e, int slop, boolean inOrder)
MACRO for SpanNearQuery containing three SpanTerm queries

    return snear(st(s), st(m), st(e), slop, inOrder);
  
public org.apache.lucene.search.spans.SpanNearQuerysnear(org.apache.lucene.search.spans.SpanQuery s, org.apache.lucene.search.spans.SpanQuery m, org.apache.lucene.search.spans.SpanQuery e, int slop, boolean inOrder)
MACRO for SpanNearQuery containing three SpanQueries

    return new SpanNearQuery(new SpanQuery[] { s, m, e }, slop, inOrder);
  
public org.apache.lucene.search.spans.SpanNotQuerysnot(org.apache.lucene.search.spans.SpanQuery i, org.apache.lucene.search.spans.SpanQuery e)
MACRO for SpanNotQuery

    return new SpanNotQuery(i,e);
  
public org.apache.lucene.search.spans.SpanOrQuerysor(java.lang.String s, java.lang.String e)
MACRO for SpanOrQuery containing two SpanTerm queries

    return sor(st(s), st(e));
  
public org.apache.lucene.search.spans.SpanOrQuerysor(org.apache.lucene.search.spans.SpanQuery s, org.apache.lucene.search.spans.SpanQuery e)
MACRO for SpanOrQuery containing two SpanQueries

    return new SpanOrQuery(new SpanQuery[] { s, e });
  
public org.apache.lucene.search.spans.SpanOrQuerysor(java.lang.String s, java.lang.String m, java.lang.String e)
MACRO for SpanOrQuery containing three SpanTerm queries

    return sor(st(s), st(m), st(e));
  
public org.apache.lucene.search.spans.SpanOrQuerysor(org.apache.lucene.search.spans.SpanQuery s, org.apache.lucene.search.spans.SpanQuery m, org.apache.lucene.search.spans.SpanQuery e)
MACRO for SpanOrQuery containing two SpanQueries

    return new SpanOrQuery(new SpanQuery[] { s, m, e });
  
public org.apache.lucene.search.spans.SpanTermQueryst(java.lang.String s)
MACRO for SpanTermQuery

    return new SpanTermQuery(new Term(FIELD,s));
  
public static org.apache.lucene.index.Term[]ta(java.lang.String[] s)
helper for generating MultiPhraseQueries

    Term[] t = new Term[s.length];
    for (int i = 0; i < s.length; i++) {
      t[i] = new Term(FIELD, s[i]);
    }
    return t;
  
public voidtearDown()


       
    searcher.close();
  
public voidtestNoop()
Placeholder: JUnit freaks if you don't have one test ... making class abstract doesn't help

    /* NOOP */