PyLucene 3.4.0-1 import
[pylucene.git] / test / test_bug1842.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_Bug1842(unittest.TestCase):
19
20     def setUp(self):
21
22         self.analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)
23         self.d1 = RAMDirectory()
24         
25         w1 = IndexWriter(self.d1, self.analyzer, True,
26                          IndexWriter.MaxFieldLength.LIMITED)
27         doc1 = Document()
28         doc1.add(Field("all", "blah blah blah Gesundheit",
29                        Field.Store.NO, Field.Index.ANALYZED,
30                        Field.TermVector.YES))
31         doc1.add(Field('id', '1',
32                        Field.Store.YES, Field.Index.NOT_ANALYZED))
33         w1.addDocument(doc1)
34         w1.optimize()
35         w1.close()
36
37     def tearDown(self):
38         pass
39
40     def test_bug1842(self):
41
42         reader = IndexReader.open(self.d1, True)
43         searcher = IndexSearcher(self.d1, True)
44         q = TermQuery(Term("id", '1'))
45         topDocs = searcher.search(q, 50)
46         freqvec = reader.getTermFreqVector(topDocs.scoreDocs[0].doc, "all")
47         terms = list(freqvec.getTerms())
48         terms.sort()
49         self.assert_(terms == ['blah', 'gesundheit'])
50
51         freqs = freqvec.getTermFrequencies()
52         self.assert_(freqs == [3, 1])
53
54 if __name__ == '__main__':
55     import lucene
56     lucene.initVM()
57     unittest.main()