views:

500

answers:

2

Am using this version of Lucene highlighter.net API. I want to get a phrase highlighted only when ALL of its words are present in the search results..But,am not able to do so....for example, if my input search string is "Leading telecom company", then the API only highlights "telecom" in the results if the result does not contain the words "leading" and "company"...

Here is the code i'm using:

SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter();

            var appData = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
            var folderpath = System.IO.Path.Combine(appData, "MyFolder");

            indexReader = IndexReader.Open(folderpath);

            Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(finalQuery.Rewrite(indexReader)));


            highlighter.SetTextFragmenter(new SimpleFragmenter(800));

            int maxNumFragmentsRequired = 5;

            string highlightedText = string.Empty;

            TokenStream tokenStream = this._analyzer.TokenStream(fieldName, new System.IO.StringReader(fieldText));

            highlightedText = highlighter.GetBestFragments(tokenStream, fieldText, maxNumFragmentsRequired, "...");

            return highlightedText;

Please help!

A: 

have a look at the highlighters unit test - your use case could be somewhere in there.

ax
A: 

Check out the answers to this question. As it is now, the highlighter does not understand phrase queries. It just uses a QueryTermExtractor and gets a list of words to highlight.

itsadok