Ejemplo n.º 1
0
 public static SearchSchema AddFields(this SearchSchema schema, IEnumerable <Field> fields)
 {
     foreach (var field in fields)
     {
         schema.Fields[field.Name] = field.ToSearchField();
     }
     return(schema);
 }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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());
            }
        }