本文整理汇总了Python中lucene.IndexSearcher.setSimilarity方法的典型用法代码示例。如果您正苦于以下问题:Python IndexSearcher.setSimilarity方法的具体用法?Python IndexSearcher.setSimilarity怎么用?Python IndexSearcher.setSimilarity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lucene.IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.setSimilarity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSimple
# 需要导入模块: from lucene import IndexSearcher [as 别名]
# 或者: from lucene.IndexSearcher import setSimilarity [as 别名]
def testSimple(self):
class SimpleSimilarity(PythonSimilarity):
def lengthNorm(_self, field, numTerms):
return 1.0
def queryNorm(_self, sumOfSquaredWeights):
return 1.0
def tf(_self, freq):
return freq
def sloppyFreq(_self, distance):
return 2.0
def idfTerms(_self, terms, searcher):
return 1.0
def idf(_self, docFreq, numDocs):
return 1.0
def coord(_self, overlap, maxOverlap):
return 1.0
def scorePayload(_self, docId, fieldName, start, end, payload,
offset, length):
return 1.0
self.indexSingleFieldDocs([Field("contents", "x", Field.Store.YES,
Field.Index.ANALYZED)])
searcher = IndexSearcher(self.directory)
searcher.setSimilarity(SimpleSimilarity())
query = TermQuery(Term("contents", "x"))
explanation = searcher.explain(query, 0)
print explanation
scoreDocs = searcher.search(query, 50).scoreDocs
self.assertEqual(1, len(scoreDocs))
self.assertEqual(scoreDocs[0].score, 1.0)
del searcher