本文整理汇总了Python中lucene.IndexSearcher.getIndexReader方法的典型用法代码示例。如果您正苦于以下问题:Python IndexSearcher.getIndexReader方法的具体用法?Python IndexSearcher.getIndexReader怎么用?Python IndexSearcher.getIndexReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lucene.IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.getIndexReader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query
# 需要导入模块: from lucene import IndexSearcher [as 别名]
# 或者: from lucene.IndexSearcher import getIndexReader [as 别名]
def query(indexName, queryString):
indSearcher = IndexSearcher(SimpleFSDirectory(File(indexName)))
qp = QueryParser(Version.LUCENE_CURRENT, "content", StandardAnalyzer(Version.LUCENE_CURRENT))
qp.setDefaultOperator(qp.Operator.AND)
query = qp.parse(queryString.replace("-","_"))
aux = indSearcher.search(query, 100)
results = aux.scoreDocs
hits = aux.totalHits
ir = indSearcher.getIndexReader()
#results = collector.topDocs()
i = 0
res = []
for r in results:
doc = ir.document(i)
res.insert(i, doc.get('id'))
i+=1
return res
示例2: query
# 需要导入模块: from lucene import IndexSearcher [as 别名]
# 或者: from lucene.IndexSearcher import getIndexReader [as 别名]
def query(indexName, queryFile, runName):
indReader = IndexReader.open(SimpleFSDirectory(File(indexName)))
indSearcher = IndexSearcher(indReader)
ir = indSearcher.getIndexReader()
qp = QueryParser(Version.LUCENE_CURRENT, "content", StandardAnalyzer(Version.LUCENE_CURRENT))
f = open('results-'+runName, 'w')
while(True):
id = queryFile.readline()
if id == "":
break
id = id.replace("C","")
id = id.replace("\n","")
queryString = queryFile.readline()
queryString = queryString.replace("?","")
queryString = queryString.replace("*","")
queryString = queryString.replace("-","_")
queryString = queryString.replace("\n","")
query = qp.parse(queryString)
queryFile.readline()
returnedDocs = 1000
collector = TopScoreDocCollector.create(returnedDocs, True)
indSearcher.search(query, collector)
hits = collector.topDocs().scoreDocs
size = len(hits)
print "Total hits for query " +id+ ": "+str(size)
i = 0
for hit in hits:
docId = hits[i].doc
score = hits[i].score
doc = ir.document(docId)
j = i + 1
f.write(id + " 0 " + doc.get('id') + " " + str(j) + " " + str(score) +" " + runName +"\n")
i+=1
f.close()