<commit_before>﻿using System.Linq;
using NUnit.Framework;
using Nest.Tests.MockData.Domain;

namespace Nest.Tests.Integration.Integration
{
	[TestFixture]
	public class HighlightIntegrationTests : IntegrationTests
	{
		[Test]
		public void TestHighlight()
		{
			var result = this._client.Search<ElasticSearchProject>(s => s
			  .From(0)
			  .Size(10)
			  .Query(q => q
				.QueryString(qs => qs
				  .OnField(e => e.Content)
				  .Query("null or null*")
				)
			  )
			  .Highlight(h => h
				.PreTags("<b>")
				.PostTags("</b>")
				.OnFields(
				  f => f
					.OnField(e => e.Content)
					.PreTags("<em>")
					.PostTags("</em>")
				)
			  )
			);
			Assert.IsTrue(result.IsValid);
			Assert.DoesNotThrow(() => result.Highlights.Count());
			Assert.IsNotNull(result.Highlights);
			Assert.Greater(result.Highlights.Count(), 0);
			Assert.True(result.Highlights.All(h => h.Value != null));

			Assert.True(result.Highlights.All(h => h.Value.All(hh => !hh.Value.DocumentId.IsNullOrEmpty())));

			var id = result.Documents.First().Id.ToString();
			var highlights = result.Highlights[id];	
			Assert.NotNull(highlights);
			Assert.NotNull(highlights["content"]);
			Assert.Greater(highlights["content"].Highlights.Count(), 0);
		}

		[Test]
		public void TestHighlightNoNullRef()
		{
			var result = this._client.Search<ElasticSearchProject>(s => s
			  .From(0)
			  .Size(10)
			  .Query(q => q
				.QueryString(qs => qs
				  .Query("elasticsearch.pm")
				)
			  )
			  .Highlight(h => h
				.PreTags("<b>")<commit_msg>slightly improved highlight integration test to show of both ways to get to your highlight<commit_after>﻿using System.Linq;
using NUnit.Framework;
using Nest.Tests.MockData.Domain;

namespace Nest.Tests.Integration.Integration
{
	[TestFixture]
	public class HighlightIntegrationTests : IntegrationTests
	{
		[Test]
		public void TestHighlight()
		{
			var result = this._client.Search<ElasticSearchProject>(s => s
			  .From(0)
			  .Size(10)
			  .Query(q => q
				.QueryString(qs => qs
				  .OnField(e => e.Content)
				  .Query("null or null*")
				)
			  )
			  .Highlight(h => h
				.PreTags("<b>")
				.PostTags("</b>")
				.OnFields(
				  f => f
					.OnField(e => e.Content)
					.PreTags("<em>")
					.PostTags("</em>")
				)
			  )
			);
			Assert.IsTrue(result.IsValid);
			Assert.DoesNotThrow(() => result.Highlights.Count());
			Assert.IsNotNull(result.Highlights);
			Assert.Greater(result.Highlights.Count(), 0);
			Assert.True(result.Highlights.All(h => h.Value != null));

			Assert.True(result.Highlights.All(h => h.Value.All(hh => !hh.Value.DocumentId.IsNullOrEmpty())));

			var id = result.Documents.First().Id.ToString();
			var highlights = result.Highlights[id];	
			Assert.NotNull(highlights);
			Assert.NotNull(highlights["content"]);
			Assert.Greater(highlights["content"].Highlights.Count(), 0);

			highlights = result.DocumentsWithMetaData.First().Highlight;
			Assert.NotNull(highlights);
			Assert.NotNull(highlights["content"]);
			Assert.Greater(highlights["content"].Highlights.Count(), 0);
		}

		[Test]
		public void TestHighlightNoNullRef()
		{
			var result = this._client.Search<ElasticSearchProject>(s => s
			  .From(0)
			  .Size(10)
			  .Query(q => q
				.QueryString(qs => qs
				  .Query("elasticsearch.pm")
				)
			  )
			  .Highlight(h => h
				.PreTags("<b>")
{'fraction_non_alphanumeric': 0.16611891245891844, 'fraction_numerical': 0.005079175380938153, 'mean_word_length': 3.1902377972465583, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7586595', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1127, 'n_words': 185}