PyLucene 3.4.0-1 import
[pylucene.git] / test / test_bug1763.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 import unittest
16 from lucene import *
17
18 class Test_Bug1763(unittest.TestCase):
19
20     def setUp(self):
21
22         self.analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)
23         self.d1 = RAMDirectory()
24         self.d2 = RAMDirectory()
25         
26         w1, w2 = [IndexWriter(d, self.analyzer, True,
27                               IndexWriter.MaxFieldLength.LIMITED)
28                   for d in [self.d1, self.d2]]
29         doc1 = Document()
30         doc2 = Document()
31         doc1.add(Field("all", "blah blah double blah Gesundheit",
32                        Field.Store.NO, Field.Index.ANALYZED))
33         doc1.add(Field('id', '1', Field.Store.YES, Field.Index.NO))
34         doc2.add(Field("all", "a quick brown test ran over the lazy data",
35                        Field.Store.NO, Field.Index.ANALYZED))
36         doc2.add(Field('id', '2',
37                        Field.Store.YES, Field.Index.NO))
38         w1.addDocument(doc1)
39         w2.addDocument(doc2)
40         for w in [w1, w2]:
41             w.optimize()
42             w.close()
43
44     def tearDown(self):
45         pass
46
47     def test_bug1763(self):
48             
49         w1 = IndexWriter(self.d1, self.analyzer, True,
50                          IndexWriter.MaxFieldLength.LIMITED)
51         w1.addIndexes([IndexReader.open(self.d2, True)])
52         w1.optimize()
53         w1.close()
54
55         searcher = IndexSearcher(self.d1, True)
56         q = QueryParser(Version.LUCENE_CURRENT, 'all',
57                         self.analyzer).parse('brown')
58         topDocs = searcher.search(q, 50)
59         self.assertEqual(searcher.doc(topDocs.scoreDocs[0].doc).get('id'), '2')
60
61
62 if __name__ == '__main__':
63     import lucene
64     lucene.initVM()
65     unittest.main()