Answer the question
In order to leave comments, you need to log in
Word highlighting lucene.net?
I'm doing a full text search for the web using lucene on asp.net. Everything works great, except for keyword highlighting. More precisely, it works and highlights for all queries except wildcardQuery, i.e. requests like: "by * sk", etc. I do everything by default:
Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser("text", analyzer);
Query query = parser.Parse(src_txt);
IndexSearcher searcher = new IndexSearcher(path);
Hits hits = searcher.Search(query);
Lucene.Net.Highlight.Formatter formatter = new Lucene.Net.Highlight.SimpleHTMLFormatter(
"<span class='find'>", "</span>");
Lucene.Net.Highlight.SimpleFragmenter fragmenter = new Lucene.Net.Highlight.SimpleFragmenter(300);
Lucene.Net.Highlight.QueryScorer scorer = new Lucene.Net.Highlight.QueryScorer(query);
Lucene.Net.Highlight.Highlighter highlighter = new Lucene.Net.Highlight.Highlighter(formatter, scorer);
highlighter.SetTextFragmenter(fragmenter);
Document doc = hits.Doc(i);
string tr = Server.HtmlEncode(doc.Get("text"));
TokenStream ts = analyzer.TokenStream("", new System.IO.StringReader(tr));
string result = highlighter.GetBestFragment(ts, tr);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question