lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James O'Rourke <ja...@bittorrent.com>
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)
     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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message