PyLucene 3.4.0-1 import
[pylucene.git] / test / test_Not.py
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
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
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 # ====================================================================
14
15 from unittest import TestCase, main
16 from lucene import *
17
18
19 class NotTestCase(TestCase):
20     """
21     Unit tests ported from Java Lucene
22     """
23   
24     def testNot(self):
25
26         store = RAMDirectory()
27         writer = IndexWriter(store, SimpleAnalyzer(Version.LUCENE_CURRENT),
28                              True, IndexWriter.MaxFieldLength.LIMITED)
29
30         d1 = Document()
31         d1.add(Field("field", "a b", Field.Store.YES, Field.Index.ANALYZED))
32
33         writer.addDocument(d1)
34         writer.optimize()
35         writer.close()
36
37         searcher = IndexSearcher(store, True)
38         query = QueryParser(Version.LUCENE_CURRENT, "field",
39                             SimpleAnalyzer(Version.LUCENE_CURRENT)).parse("a NOT b")
40
41         topDocs = searcher.search(query, 50)
42         self.assertEqual(0, topDocs.totalHits)
43
44
45 if __name__ == "__main__":
46     import sys, lucene
47     lucene.initVM()
48     if '-loop' in sys.argv:
49         sys.argv.remove('-loop')
50         while True:
51             try:
52                 main()
53             except:
54                 pass
55     else:
56          main()