1 # ====================================================================
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 # ====================================================================
15 from lucene import IndexWriter, IndexReader
16 from lia.indexing.BaseIndexingTestCase import BaseIndexingTestCase
19 class DocumentDeleteTest(BaseIndexingTestCase):
21 def testDeleteBeforeIndexMerge(self):
23 reader = IndexReader.open(self.dir, False)
24 self.assertEqual(2, reader.maxDoc())
25 self.assertEqual(2, reader.numDocs())
26 reader.deleteDocument(1)
28 self.assert_(reader.isDeleted(1))
29 self.assert_(reader.hasDeletions())
30 self.assertEqual(2, reader.maxDoc())
31 self.assertEqual(1, reader.numDocs())
35 reader = IndexReader.open(self.dir, True)
37 self.assertEqual(2, reader.maxDoc())
38 self.assertEqual(1, reader.numDocs())
42 def testDeleteAfterIndexMerge(self):
44 reader = IndexReader.open(self.dir, False)
45 self.assertEqual(2, reader.maxDoc())
46 self.assertEqual(2, reader.numDocs())
47 reader.deleteDocument(1)
50 writer = IndexWriter(self.dir, self.getAnalyzer(), False,
51 IndexWriter.MaxFieldLength.UNLIMITED)
55 reader = IndexReader.open(self.dir, True)
57 self.assert_(not reader.isDeleted(1))
58 self.assert_(not reader.hasDeletions())
59 self.assertEqual(1, reader.maxDoc())
60 self.assertEqual(1, reader.numDocs())