| 3 | namespace SearchService.Data; |
| 4 | |
| 5 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…