我已经阅读了一些关于在 Lucene 中突出显示搜索词的教程,并提出了如下代码:
(...)
query = parser.parse(query_string)
for scoreDoc in searcher.search(query, 50).scoreDocs:
doc = searcher.doc(scoreDoc.doc)
filename = doc.get("filename")
print filename
found_paraghaph = fetch_from_my_text_library(filename)
stream = lucene.TokenSources.getTokenStream("contents", found_paraghaph, analyzer);
scorer = lucene.Scorer(query, "contents", lucene.CachingTokenFilter(stream))
highligter = lucene.Highligter(scorer)
fragment = highligter.getBestFragment(analyzer, "contents", found_paraghaph)
print '>>>' + fragment
但这一切都以错误结束:
Traceback (most recent call last):
File "./search.py", line 76, in <module>
scorer = lucene.Scorer(query, "contents", lucene.CachingTokenFilter(stream))
NotImplementedError: ('instantiating java class', <type 'Scorer'>)
所以,我猜,Lucene 的这一部分还没有在 pyLucene 中实现。还有其他方法吗?