Is there anyway to do highlighting when using a WildcardQuery when
there is no IndexReader available? I simply want to do it with a
chunk of text, but it fails because the WildcardQuery needs to call
rewrite - but doesn't know about the IndexReader.
Code (using PyLucene-2.0.0 - can translate to java if like)
def gethighlightedfragments(text, searchString,
fragmentLength = 50, numFragments = 3, opening= '<span class=
\"highlight\">', closing = '</span>'):
""" Returns a list of text fragments with returns included for
80 char max width """
""" Defaults to OR operator which is good for formatting """
analyzer = StandardAnalyzer()
#print text
strs = searchString.split()
bq = BooleanQuery()
for s in strs:
print s
q = WildcardQuery(Term('f', '*' + s + '*'))
#print q.toString()
bq.add(q, BooleanClause.Occur.SHOULD)
#print bq.toString()
scorer = QueryScorer(bq)
formatter = SimpleHTMLFormatter(opening, closing)
highlighter = Highlighter(formatter, scorer)
fragmenter = SimpleFragmenter(fragmentLength)
highlighter.setTextFragmenter(fragmenter)
tokenStream = analyzer.tokenStream('f', StringReader(text))
return highlighter.getBestFragments(tokenStream, text,
numFragments)
Basically, I want to show partial word matches also.
James
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]