开发者

Highlighting in Solr

开发者 https://www.devze.com 2023-03-08 04:12 出处:网络
I use Solrnet to develop a search engine. In my application, I have a fie开发者_StackOverflowld called file_contents which I use for highlighting. Am able to get the highlights without a problem. Now

I use Solrnet to develop a search engine. In my application, I have a fie开发者_StackOverflowld called file_contents which I use for highlighting. Am able to get the highlights without a problem. Now I need to format it. For example, if the keyword occurs multiple times in the field, I have to display it lime what google does. May be like this.

GSMArena.com: Toshiba GSM cellphones. ... Toshiba phones. Toshiba. Filters. Available · Coming soon · Smartphone · Touchscreen · Camera · Bluetooth · Wi-Fi ...

Multiple snippets here are separated by "...". I need to achieve something like this. Am able to get multiple snippets. But how do I deal with the separating?

Regards

Vignesh


Without much to go on in the question about what format the snippets data is in, assuming it's in an array called YourArrayOfSnippets, you'd do:

string joined_snippets = string.Join(" ... ", YourArrayOfSnippets);

And then use joined_snippets however you see fit.

In fact, SolrNet has a wiki page on highlighting with an example of how you might handle highlighting results, and even shows the use of Join. Basically:

var results = solr.Query(new SolrQueryByField("features", "noise"), new QueryOptions {
    Highlight = new HighlightingParameters {
        Fields = new[] {"features"},
    }
});
foreach (var h in results.Highlights[results[0].Id]) {
    Console.WriteLine("{0}: {1}", h.Key, string.Join(", ", h.Value.ToArray()));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消