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 unittest import TestCase, main
19 class DocBoostTestCase(TestCase):
21 Unit tests ported from Java Lucene
24 def testDocBoost(self):
26 store = RAMDirectory()
27 writer = IndexWriter(store, SimpleAnalyzer(), True,
28 IndexWriter.MaxFieldLength.LIMITED)
30 f1 = Field("field", "word", Field.Store.YES, Field.Index.ANALYZED)
31 f2 = Field("field", "word", Field.Store.YES, Field.Index.ANALYZED)
41 d1.add(f1) # boost = 1
42 d2.add(f2) # boost = 2
43 d3.add(f1) # boost = 3
44 d4.add(f2) # boost = 4
46 writer.addDocument(d1)
47 writer.addDocument(d2)
48 writer.addDocument(d3)
49 writer.addDocument(d4)
55 class collector(PythonCollector):
56 def __init__(_self, scores):
57 super(collector, _self).__init__()
60 def collect(_self, doc, score):
61 _self.scores[doc + _self.base] = score
62 def setNextReader(_self, reader, docBase):
64 def acceptsDocsOutOfOrder(_self):
67 IndexSearcher(store, True).search(TermQuery(Term("field", "word")),
72 self.assert_(score > lastScore)
76 if __name__ == "__main__":
79 if '-loop' in sys.argv:
80 sys.argv.remove('-loop')