Created
March 14, 2017 14:08
-
-
Save lindstromhenrik/61b8f504127b89f4ebee1e62a1da7df5 to your computer and use it in GitHub Desktop.
Highlighting all attachment fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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