Skip to content

Commit

Permalink
fix: added Highlight for Wildcard and Morphology search
Browse files Browse the repository at this point in the history
Refs: SITKO-CORE-T-24
  • Loading branch information
IgorAlymov committed Aug 8, 2024
1 parent cf5bc78 commit 900e26d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ private SearchDescriptor<TSearchModel> GetSearchRequest(SearchDescriptor<TSearch
{
descriptor.Highlight(h =>
h.Fields(fs => fs
.Field(p => p.Title)
.PreTags(Options.PreTags)
.PostTags(Options.PostTags)));
.Field(p => p.Title)
.PreTags(Options.PreTags)
.PostTags(Options.PostTags),
fs => fs
.Field(p => p.Content)
.PreTags(Options.PreTags)
.PostTags(Options.PostTags)));
}

return descriptor
Expand All @@ -295,7 +299,7 @@ private AnalysisDescriptor CreateAnalysisDescriptor(AnalysisDescriptor a) =>
.Filters("lowercase", "stop", "snowball", StemmerName))
.Custom(CustomCharFilterAnalyze, ca => ca
.Tokenizer("standard")
.Filters("lowercase", "stop", "snowball", StemmerName)
.Filters("lowercase", "stop")
.CharFilters(CustomCharFilter))
)
.CharFilters(descriptor =>
Expand Down
11 changes: 7 additions & 4 deletions tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ public async Task IncorrectLayoutKeyboardTestAsync()
result.Length.Should().Be(1);
}

[Fact]
public async Task HighlightingTestAsync()

[Theory(DisplayName = "HighlightingTest")]
[InlineData("играют", SearchType.Wildcard)]
[InlineData("компьютерный", SearchType.Morphology)]
public async Task HighlightingTestAsync(string searchText, SearchType searchType)
{
var scope = await GetScopeAsync();
var provider = scope.GetService<TestModelProvider>();
Expand All @@ -206,15 +209,15 @@ public async Task HighlightingTestAsync()

var firstModel = new TestModel
{
Title = "Геймеры играют в компьютерные игры.", Description = "MMI", Url = "mmicentre"
Title = "Геймеры играют в компьютерные игры.", Description = "Геймеры играют в компьютерные игры.", Url = "mmicentre"
};
var secondModel = new TestModel { Title = "MMI", Description = "mmicentre", Url = "mmicentre" };
provider.AddModel(firstModel).AddModel(secondModel);

await searchProvider.AddOrUpdateEntitiesAsync(provider.Models.ToArray());
await Task.Delay(TimeSpan.FromSeconds(5));

var result = await searchProvider.SearchAsync("компьютерный", 10, SearchType.Morphology, true);
var result = await searchProvider.SearchAsync(searchText, 10, searchType, true);
result.Length.Should().Be(1);
result.First().ResultModel.Highlight.Count.Should().Be(1);
result.First().ResultModel.Highlight.First().Value.First().Contains("<span class='highlight'>").Should().BeTrue();
Expand Down

0 comments on commit 900e26d

Please sign in to comment.