Umbraco Examine Search Results Highlighting Problem
Hi all,
I'm experiencing some troubles when trying to highlight search results of terms that are partial words
for example if my website contains the word "basis", and i will search for basis, it will find it and highlight it, but if i search for the word "basi" it will find the right results but the code below will not work this time, thus i will get no results:
Umbraco Examine Search Results Highlighting Problem
Hi all,
I'm experiencing some troubles when trying to highlight search results of terms that are partial words
for example if my website contains the word "basis", and i will search for basis, it will find it and highlight it, but if i search for the word "basi" it will find the right results but the code below will not work this time, thus i will get no results:
Lucene.Net.Search.Query query = this.GetQueryParser(highlightField).Parse(luceneRawQuery);
did anyone experienced it before?
Thanks a lot :)
Yuval
Hi,
You can try the following:
public string GetHighlight(string value, string highlightField, Lucene.Net.Search.IndexSearcher searcher, string luceneRawQuery) {
var finalQuery = new BooleanQuery(); string[] terms = luceneRawQuery.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); foreach (string term in terms){
var fuzzyQuery = new FuzzyQuery(new Lucene.Net.Index.Term(highlightField, term), MIN_SIMILARITY, PREFIX_LENGTH);
finalQuery.Add(new BooleanClause(fuzzyQuery, BooleanClause.Occur.MUST));
}
QueryScorer fragmentScorer = new QueryScorer(finalQuery.Rewrite(searcher.GetIndexReader()));
Lucene.Net.Highlight.Highlighter highlighter = new Highlighter(this.HighlightFormatter, fragmentScorer); Lucene.Net.Analysis.TokenStream tokenStream = this.HighlightAnalyzer.TokenStream(highlightField, new System.IO.StringReader(value)); string result = highlighter.GetBestFragments(tokenStream, value, this.MaxNumHighlights, this.Separator);
return result;
}
Regards,
Moshe
is working on a reply...