MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / SearchInitializer

Class SearchInitializer

SearchService/Data/SearchInitializer.cs:5–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3namespace SearchService.Data;
4
5public static class SearchInitializer
6{
7 public static async Task EnsureIndexExists(ITypesenseClient client)
8 {
9 const string schemaName = "questions";
10
11 try
12 {
13 await client.RetrieveCollection(schemaName);
14 Console.WriteLine($"Collection '{schemaName}' not found. Creating...");
15 return;
16 }
17 catch (TypesenseApiNotFoundException)
18 {
19 Console.WriteLine($"Collection '{schemaName}' not found. Creating...");
20 }
21
22 var schema = new Schema(schemaName, new List<Field>
23 {
24 new("id", FieldType.String),
25 new("title", FieldType.String),
26 new("content", FieldType.String),
27 new("tags", FieldType.StringArray),
28 new("createdAt", FieldType.Int64),
29 new("answerCount", FieldType.Int32),
30 new("hasAcceptedAnswer", FieldType.Bool)
31 })
32 {
33 DefaultSortingField = "createdAt"
34 };
35
36 await client.CreateCollection(schema);
37 Console.WriteLine($"Created Typesense collection '{schemaName}'.");
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…