Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexReader.deleteDocument()


        IndexReader reader = IndexReader.open(dir);
        Term aaa = new Term("content", "aaa");
        Term bbb = new Term("content", "bbb");
        Term ccc = new Term("content", "ccc");
        assertEquals(37, reader.docFreq(ccc));
        reader.deleteDocument(0);
        assertEquals(37, reader.docFreq(aaa));
        dir.tweakBufferSizes();
        reader.deleteDocument(4);
        assertEquals(reader.docFreq(bbb), 37);
        dir.tweakBufferSizes();
View Full Code Here


        Term ccc = new Term("content", "ccc");
        assertEquals(37, reader.docFreq(ccc));
        reader.deleteDocument(0);
        assertEquals(37, reader.docFreq(aaa));
        dir.tweakBufferSizes();
        reader.deleteDocument(4);
        assertEquals(reader.docFreq(bbb), 37);
        dir.tweakBufferSizes();

        IndexSearcher searcher = new IndexSearcher(reader);
        ScoreDoc[] hits = searcher.search(new TermQuery(bbb), null, 1000).scoreDocs;
View Full Code Here

    /** fetch the compressed string field and compare it's content with the original one */
    String stringFldCompressedTest = docFromReader.get("stringCompressed");
    assertTrue(stringFldCompressedTest.equals(binaryValCompressed));
   
    /** delete the document from index */
    reader.deleteDocument(0);
    assertEquals(0, reader.numDocs());
   
    reader.close();
   
  }
View Full Code Here

    Hits hits = searcher.search(q);
    log("Got "+hits.length()+" results");
    assertEquals("must match all "+N+" docs, not only "+hits.length()+" docs!",N,hits.length());
    if (deleteInFront) {
      log("deleting hits that was not yet retrieved!");
      reader.deleteDocument(reader.maxDoc()-1);
      reader.deleteDocument(reader.maxDoc()-2);
      reader.deleteDocument(reader.maxDoc()-3);
    }
    try {
      for (int i = 0; i < hits.length(); i++) {
View Full Code Here

    log("Got "+hits.length()+" results");
    assertEquals("must match all "+N+" docs, not only "+hits.length()+" docs!",N,hits.length());
    if (deleteInFront) {
      log("deleting hits that was not yet retrieved!");
      reader.deleteDocument(reader.maxDoc()-1);
      reader.deleteDocument(reader.maxDoc()-2);
      reader.deleteDocument(reader.maxDoc()-3);
    }
    try {
      for (int i = 0; i < hits.length(); i++) {
        int id = hits.id(i);
View Full Code Here

    assertEquals("must match all "+N+" docs, not only "+hits.length()+" docs!",N,hits.length());
    if (deleteInFront) {
      log("deleting hits that was not yet retrieved!");
      reader.deleteDocument(reader.maxDoc()-1);
      reader.deleteDocument(reader.maxDoc()-2);
      reader.deleteDocument(reader.maxDoc()-3);
    }
    try {
      for (int i = 0; i < hits.length(); i++) {
        int id = hits.id(i);
        assertEquals("Hit "+i+" has doc id "+hits.id(i)+" instead of "+i,i,hits.id(i));
View Full Code Here

        assertEquals("Hit "+i+" has doc id "+hits.id(i)+" instead of "+i,i,hits.id(i));
        if ((intermittent && (i==50 || i==250 || i==950)) || //100-yes, 200-no, 400-yes, 800-no, 1600-yes
            (!intermittent && (k<2 || (i>0 && i%k==0)))) {
          Document doc = hits.doc(id);
          log("Deleting hit "+i+" - doc "+doc+" with id "+id);
          reader.deleteDocument(id);
        }
        if (intermittent) {
          // check internal behavior of Hits (go 50 ahead of getMoreDocs points because the deletions cause to use more of the available hits)
          if (i==150 || i==450 || i==1650) {
            assertTrue("Hit "+i+": hits should have checked for deletions in last call to getMoreDocs()",hits.debugCheckedForDeletions);
View Full Code Here

    while (numDeleted < numToDelete) {
      double delRate = ((double) (numToDelete-numDeleted))/r.numDocs();
      TermDocs termDocs = r.termDocs(null);
      while (termDocs.next() && numDeleted < numToDelete) {
        if (random.nextDouble() <= delRate) {
          r.deleteDocument(termDocs.doc());
          numDeleted++;
        }
      }
      termDocs.close();
    }
View Full Code Here

    addDocument(iw, "Hello, earth!");
    addDocument(iw, "All work and no play makes wendy a dull girl");
    iw.close();

    IndexReader unoptimizedReader = IndexReader.open(dir);
    unoptimizedReader.deleteDocument(2);

    InstantiatedIndex ii;
    try {
     ii = new InstantiatedIndex(unoptimizedReader);
    } catch (Exception e) {
View Full Code Here

    assertEquals(air.hasDeletions(), tir.hasDeletions());
    assertEquals(air.maxDoc(), tir.maxDoc());
    assertEquals(air.numDocs(), tir.numDocs());
    assertEquals(air.numDeletedDocs(), tir.numDeletedDocs());

    air.deleteDocument(3);
    tir.deleteDocument(3);

    assertEquals(air.isCurrent(), tir.isCurrent());
    assertEquals(air.hasDeletions(), tir.hasDeletions());
    assertEquals(air.maxDoc(), tir.maxDoc());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.