FileDocCategorySizeDatePackage
TestMatchAllDocsQuery.javaAPI DocApache Lucene 2.0.02630Fri May 26 09:54:10 BST 2006org.apache.lucene.search

TestMatchAllDocsQuery

public class TestMatchAllDocsQuery extends TestCase
Tests MatchAllDocsQuery.
author
Daniel Naber

Fields Summary
Constructors Summary
Methods Summary
private voidaddDoc(java.lang.String text, org.apache.lucene.index.IndexWriter iw)

    Document doc = new Document();
    doc.add(new Field("key", text, Field.Store.YES, Field.Index.TOKENIZED));
    iw.addDocument(doc);
  
public voidtestEquals()

    Query q1 = new MatchAllDocsQuery();
    Query q2 = new MatchAllDocsQuery();
    assertTrue(q1.equals(q2));
    q1.setBoost(1.5f);
    assertFalse(q1.equals(q2));
  
public voidtestQuery()

    RAMDirectory dir = new RAMDirectory();
    IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true);
    addDoc("one", iw);
    addDoc("two", iw);
    addDoc("three four", iw);
    iw.close();
    
    IndexSearcher is = new IndexSearcher(dir);
    Hits hits = is.search(new MatchAllDocsQuery());
    assertEquals(3, hits.length());

    // some artificial queries to trigger the use of skipTo():
    
    BooleanQuery bq = new BooleanQuery();
    bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
    bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
    hits = is.search(bq);
    assertEquals(3, hits.length());

    bq = new BooleanQuery();
    bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
    bq.add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST);
    hits = is.search(bq);
    assertEquals(1, hits.length());

    // delete a document:
    is.getIndexReader().deleteDocument(0);
    hits = is.search(new MatchAllDocsQuery());
    assertEquals(2, hits.length());
    
    is.close();