Skip to content

Commit

Permalink
Merge pull request #997 from IgorAlymov/SITKO-CORE-T-21
Browse files Browse the repository at this point in the history
feat: update searching by numbers
  • Loading branch information
pogromistik authored Jul 31, 2024
2 parents defd56f + 469b99a commit f718071
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Sitko.Core.Search.OpenSearch/OpenSearchSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,15 @@ private static SearchDescriptor<TSearchModel> GetSearchRequest(SearchDescriptor<
switch (searchType)
{
case SearchType.Morphology:
descriptor.Query(q => q.QueryString(qs => qs.Query(names)));
descriptor.Query(q => q.QueryString(qs =>
qs.Fields(fieldsDescriptor => fieldsDescriptor.Field(searchModel => searchModel.Title)
.Field(searchModel => searchModel.Content)).Query(names)));
break;
case SearchType.Wildcard:
descriptor.Query(q =>
q.QueryString(qs => qs.Query($"*{names}*").AnalyzeWildcard()));
q.QueryString(qs => qs.Fields(fieldsDescriptor => fieldsDescriptor
.Field(searchModel => searchModel.Title)
.Field(searchModel => searchModel.Content)).Query($"*{names}*").AnalyzeWildcard()));
break;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Sitko.Core.Search.OpenSearch.Tests/OpenSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ public async Task PartialSearchRusTestAsync(int foundDocs, string searchText)
var result = await searchProvider.SearchAsync(searchText, 10, SearchType.Wildcard);
result.Length.Should().Be(foundDocs);
}

[Theory(DisplayName = "SearchByNumbersTest")]
[InlineData(2, "74", SearchType.Morphology)]
[InlineData(2, "74", SearchType.Wildcard)]
public async Task SearchByNumbersTestAsync(int foundDocs, string searchText, SearchType searchType)
{
var scope = await GetScopeAsync();
var provider = scope.GetService<TestModelProvider>();
var searchProvider = scope.GetService<ISearchProvider<TestModel, Guid>>();
await searchProvider.DeleteIndexAsync();
await searchProvider.InitAsync();
var firstGuid = Guid.Parse("dd134352-da92-4cd2-9c" + searchText + "-440be713aba5");
var secondGuid = Guid.Parse("dd134352-da92-4cd2-9c88-440be713aba5");
var thirdGuid = Guid.Parse("dd134352-da92-4cd3-9c88-440be713aba5");

var firstModel = new TestModel { Id = firstGuid, Title = "MMI", Description = "MMI", Url = $"/page/{firstGuid.ToString()}" };
var secondModel = new TestModel { Id = secondGuid, Title = "MMI", Description = searchText, Url = "mmicentre" };
var thirdModel = new TestModel { Id = thirdGuid, Title = searchText, Description = "MMI", Url = "mmicentre" };
provider.AddModel(firstModel).AddModel(secondModel).AddModel(thirdModel);

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

var result2 = await searchProvider.SearchAsync(searchText, 10, searchType);
result2.Length.Should().Be(foundDocs);
}
}

public class OpenSearchTestScope : BaseTestScope
Expand Down

0 comments on commit f718071

Please sign in to comment.