def testDeleteBeforeIndexMerge(self): reader = IndexReader.open(self.dir, False) self.assertEqual(2, reader.maxDoc()) self.assertEqual(2, reader.numDocs()) reader.deleteDocument(1) deletedDocs = MultiFields.getDeletedDocs(reader) self.assert_(deletedDocs is not None and deletedDocs.get(1)) self.assert_(reader.hasDeletions()) self.assertEqual(2, reader.maxDoc()) self.assertEqual(1, reader.numDocs()) reader.close() reader = IndexReader.open(self.dir, True) self.assertEqual(2, reader.maxDoc()) self.assertEqual(1, reader.numDocs()) reader.close()
def testDeleteAfterIndexMerge(self): reader = IndexReader.open(self.dir, False) self.assertEqual(2, reader.maxDoc()) self.assertEqual(2, reader.numDocs()) reader.deleteDocument(1) reader.close() writer = IndexWriter(self.dir, self.getAnalyzer(), False, IndexWriter.MaxFieldLength.UNLIMITED) writer.commit() writer.close() reader = IndexReader.open(self.dir, True) deletedDocs = MultiFields.getDeletedDocs(reader) self.assert_(deletedDocs is None or not deletedDocs.get(1)) self.assert_(not reader.hasDeletions()) self.assertEqual(1, reader.maxDoc()) self.assertEqual(1, reader.numDocs()) reader.close()
def main(cls, argv): indexDir = System.getProperty("index.dir") directory = SimpleFSDirectory(File(indexDir)) reader = IndexReader.open(directory, True) blt = BooksLikeThis(reader) deletedDocs = MultiFields.getDeletedDocs(reader) for id in xrange(reader.maxDoc()): if deletedDocs is not None and deletedDocs.get(id): continue doc = reader.document(id) print '' print doc.get("title").encode('utf-8') docs = blt.docsLike(id, doc, 10) if not docs: print " None like this" else: for doc in docs: print " ->", doc.get("title").encode('utf-8')