-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMockSearchService.cs
More file actions
132 lines (123 loc) · 4.82 KB
/
MockSearchService.cs
File metadata and controls
132 lines (123 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
namespace Elastic.Documentation.Search;
public class MockNavigationSearchService : INavigationSearchService
{
private static readonly List<NavigationSearchResultItem> Results =
[
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/kibana",
Title = "Kibana: Explore, Visualize, Discover Data",
Description =
"Run data analytics at speed and scale for observability, security, and search with Kibana. Powerful analysis on any data from any source.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs/explore-analyze",
Title = "Explore and analyze | Elastic Docs",
Description = "Kibana provides a comprehensive suite of tools to help you search, interact with, explore, and analyze your data effectively.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs/deploy-manage/deploy/self-managed/install-kibana",
Title = "Install Kibana | Elastic Docs",
Description =
"Information on how to set up Kibana and get it running, including downloading, enrollment with Elasticsearch cluster, and configuration.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/kibana/kibana-lens",
Title = "Kibana Lens - Data visualization. Simply.",
Description =
"Kibana Lens simplifies the process of data visualization through a drag-and-drop experience, ideal for exploring logs, trends, and metrics.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs",
Title = "Elastic Docs - Elastic products, guides & reference",
Description =
"Official Elastic documentation. Explore guides for Elastic Cloud (hosted & on-prem), product documentation, how-to guides and API reference.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs/get-started/introduction",
Title = "Get started | Elastic Docs",
Description =
"Use Elasticsearch to search, index, store, and analyze data of all shapes and sizes in near real time. Kibana is the graphical user interface for Elasticsearch.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs/solutions/search/elasticsearch-basics-quickstart",
Title = "Elasticsearch basics quickstart",
Description = "Hands-on introduction to fundamental Elasticsearch concepts: indices, documents, mappings, and search via Console syntax.",
Parents = []
},
new NavigationSearchResultItem
{
Type = "doc",
Url = "https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-document",
Title = "Elasticsearch API documentation",
Description =
"Elastic provides REST APIs that are used by the UI components and can be called directly to configure and access Elasticsearch features.",
Parents = []
}
];
public async Task<NavigationSearchResponse> NavigationSearchAsync(NavigationSearchRequest request, CancellationToken ctx = default)
{
var filteredResults = Results
.Where(item =>
item.Title.Contains(request.Query, StringComparison.OrdinalIgnoreCase) ||
item.Description?.Contains(request.Query, StringComparison.OrdinalIgnoreCase) == true)
.ToList();
// Apply type filter if specified
if (!string.IsNullOrWhiteSpace(request.TypeFilter))
filteredResults = filteredResults.Where(item => item.Type == request.TypeFilter).ToList();
// Calculate aggregations before filtering
var aggregations = Results
.Where(item =>
item.Title.Contains(request.Query, StringComparison.OrdinalIgnoreCase) ||
item.Description?.Contains(request.Query, StringComparison.OrdinalIgnoreCase) == true)
.GroupBy(item => item.Type)
.ToDictionary(g => g.Key, g => (long)g.Count());
var pagedResults = filteredResults
.Skip((request.PageNumber - 1) * request.PageSize)
.Take(request.PageSize)
.ToList();
Console.WriteLine($"MockSearchService: Paged results count: {pagedResults.Count}");
await Task.Delay(1000, ctx);
return new NavigationSearchResponse
{
TotalResults = filteredResults.Count,
Results = pagedResults,
PageNumber = request.PageNumber,
PageSize = request.PageSize,
Aggregations = new NavigationSearchAggregations { Type = aggregations }
};
}
}
public class MockFullSearchService : IFullSearchService
{
public Task<FullSearchResponse> SearchAsync(FullSearchRequest request, Cancel ctx = default) =>
Task.FromResult(new FullSearchResponse
{
Results = [],
TotalResults = 0,
PageNumber = request.PageNumber,
PageSize = request.PageSize
});
}