But there are inconsistencies between the last Examine version and Lucene.Net.Contrib. The last Examine version uses the last Lucene version 4.8.0-beta00016, but Lucene.Net.Contrib uses the Lucene version 3.0.3 so if I try to call GetBestFragments I get the following exception:
'Could not load type 'Lucene.Net.Analysis.Tokenattributes.ITermAttribute' from assembly 'Lucene.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=85089178b9ac3181'.'
I've checked the Locene DLL and there is no required attribute:
My code:
public static string GetHighlight(string IndexField, IndexReader reader, string searchQuery, string highlightField)
{
string hightlightText = string.Empty;
var formatter = new SimpleHTMLFormatter("<span class=\"umbSearchHighlight\">", "</span>");
var highlighter = new Highlighter(formatter, FragmentScorer(searchQuery, highlightField, reader));
var tokenStream = new StandardAnalyzer(LuceneInfo.CurrentVersion).GetTokenStream(highlightField, new StringReader(IndexField));
string tmp = highlighter.GetBestFragments(tokenStream, IndexField, 3, "...");
if (tmp.Length > 0)
hightlightText = tmp + "...";
return hightlightText;
}
Searach function:
_examineManager.TryGetIndex(UmbracoConstants.UmbracoIndexes.ExternalIndexName, out IIndex externalIndex);
if (externalIndex.Searcher is LuceneSearcher luceneSearcher)
{
var highlight = ExamineHelper.GetHighlight(
"nodeName",
luceneSearcher.GetSearchContext().GetSearcher().IndexSearcher.IndexReader,
$"nodeName:term",
"nodeName"
);
}
Umbraco Examine Highlight result
I'm looking for a solution to Highlight the examine result. I've already checked some solutions:
https://our.umbraco.com/forum/developers/api-questions/44447-Highlight-text-in-examine-search-results-when-matching-beginning-of-words
https://our.umbraco.com/forum/developers/extending-umbraco/19329-Search-multiple-fields-for-multiple-terms-with-examine?p=0
https://our.umbraco.com/forum/using-umbraco-and-getting-started/90477-umbraco-examine-search-result-highlighting
https://our.umbraco.com/forum/developers/extending-umbraco/13571-Umbraco-Examine-Search-Results-Highlighting
But there are inconsistencies between the last Examine version and Lucene.Net.Contrib. The last Examine version uses the last Lucene version 4.8.0-beta00016, but Lucene.Net.Contrib uses the Lucene version 3.0.3 so if I try to call GetBestFragments I get the following exception: 'Could not load type 'Lucene.Net.Analysis.Tokenattributes.ITermAttribute' from assembly 'Lucene.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=85089178b9ac3181'.'
I've checked the Locene DLL and there is no required attribute:
My code:
Searach function:
is working on a reply...