Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lindstromhenrik
Created March 14, 2017 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindstromhenrik/61b8f504127b89f4ebee1e62a1da7df5 to your computer and use it in GitHub Desktop.
Save lindstromhenrik/61b8f504127b89f4ebee1e62a1da7df5 to your computer and use it in GitHub Desktop.
Highlighting all attachment fields
public static class HighlightExtensions
{
public static IQueriedSearch<TSource, TExistingQuery> WithAttachmentHighlight<TSource, TExistingQuery>(
this IQueriedSearch<TSource, TExistingQuery> search, Action<FieldHighlightRequest> highlightAction = null)
where TExistingQuery : QueryStringQuery
{
return new Search<TSource, TExistingQuery>(search, context =>
{
var fieldName = "*$$attachment";
var request = new FieldHighlightRequest(fieldName);
if (highlightAction.IsNotNull())
{
highlightAction(request);
}
context.RequestBody.Highlight.Fields.Add(request);
});
}
}
result = client.Search<MyType>()
.For("banana")
.WithAttachmentHighlight()
.GetResult();
result.Hits.First().Highlights.First().Highlights.First();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment