lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James O'Rourke <>
Subject highlighting with WildcardQuery
Date Fri, 13 Oct 2006 18:39:31 GMT
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)

     tokenStream = analyzer.tokenStream('f', StringReader(text))
     return  highlighter.getBestFragments(tokenStream, text,  

Basically, I want to show partial word matches also.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message