public static SearchSchema AddFields(this SearchSchema schema, IEnumerable <Field> fields) { foreach (var field in fields) { schema.Fields[field.Name] = field.ToSearchField(); } return(schema); }
public SearchModel(SearchSchema schema) { Facets = new List <SearchField>(); Tags = new List <SearchField>(); SelectFilter = resultFields; if (facets.Count() > 0) { // add field to facets if in facets arr foreach (var field in facets) { if (schema.Fields[field] != null && schema.Fields[field].IsFacetable) { Facets.Add(schema.Fields[field]); } } } else { foreach (var field in schema.Fields.Where(f => f.Value.IsFacetable)) { Facets.Add(field.Value); } } if (tags.Count() > 0) { foreach (var field in tags) { if (schema.Fields[field] != null && schema.Fields[field].IsFacetable) { Tags.Add(schema.Fields[field]); } } } else { foreach (var field in schema.Fields.Where(f => f.Value.IsFacetable)) { Tags.Add(field.Value); } } }
public DocumentSearchClient(IConfiguration configuration) { try { searchServiceName = configuration.GetSection("SearchServiceName")?.Value; apiKey = configuration.GetSection("SearchApiKey")?.Value; IndexName = configuration.GetSection("SearchIndexName")?.Value; idField = configuration.GetSection("KeyField")?.Value; telemetryClient.InstrumentationKey = configuration.GetSection("InstrumentationKey")?.Value; // Create an HTTP reference to the catalog index _searchClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey)); _indexClient = _searchClient.Indexes.GetClient(IndexName); Schema = new SearchSchema().AddFields(_searchClient.Indexes.Get(IndexName).Fields); Model = new SearchModel(Schema); } catch (Exception e) { throw new ArgumentException(e.Message.ToString()); } }