示例#1
0
        public async Task <Index> CreateIndexAsync(Index index)
        {
            index = await _client.Indexes.CreateAsync(index).ConfigureAwait(false);

            _indexes.TryAdd(index.Name, index);
            return(index);
        }
        protected virtual async Task <Index> GetOrCreateAzureIndex(Index index)
        {
            if (!await _client.Indexes.ExistsAsync(index.Name))
            {
                index = await _client.Indexes.CreateAsync(index);
            }

            return(index);
        }
示例#3
0
        public void CreateIndex()
        {
            var definition = new Index
            {
                Name   = IndexName,
                Fields = FieldBuilder.BuildForType <T>()
            };

            _searchServiceClient.Indexes.Create(definition);
        }
        void TransferSchema()
        {
            if (DO_NOT_COMMIT_INDEX)
            {
                return;
            }

            Console.WriteLine("Started copying old index accross.");

            try
            {
                // Get the old schema
                var legacyIndex = _legacySearchClient.Indexes.Get(Settings.LegacySearchIndex).Index;

                // delete the target index if it exists
                if (_targetSearchClient.Indexes.Exists(Settings.TargetSearchIndex))
                {
                    _targetSearchClient.Indexes.Delete(Settings.TargetSearchIndex);
                }

                // the new index - could prob just copy them directly, but may need some tweaks
                List <Microsoft.Azure.Search.Models.Field> fields = new List <Microsoft.Azure.Search.Models.Field>();

                // enumerate legacy and push to target
                foreach (var lfield in legacyIndex.Fields)
                {
                    fields.Add(new Microsoft.Azure.Search.Models.Field()
                    {
                        Name          = lfield.Name,
                        Type          = lfield.Type,
                        IsKey         = lfield.IsKey,
                        IsSearchable  = lfield.IsSearchable,
                        IsFilterable  = lfield.IsFilterable,
                        IsSortable    = lfield.IsSortable,
                        IsFacetable   = lfield.IsFacetable,
                        IsRetrievable = lfield.IsRetrievable
                    });
                }

                // the next index
                var index = new Microsoft.Azure.Search.Models.Index(Settings.TargetSearchIndex, fields);

                // create the index
                _targetSearchClient.Indexes.Create(index);

                Console.WriteLine("Successfully copied index!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem creating the index: {0}\r\n", ex.Message.ToString());
            }
        }
示例#5
0
        public IAzureIndexSearcher CreateIndexSearcher(Index index)
        {
            var client = GetOrCreateIndexClient(index.Name);

            return(new AzureIndexSearcher(index, client));
        }
        void TransferSchema()
        {
            if (DO_NOT_COMMIT_INDEX) return;

            Console.WriteLine("Started copying old index accross.");

            try
            {
                // Get the old schema
                var legacyIndex = _legacySearchClient.Indexes.Get(Settings.LegacySearchIndex).Index;

                // delete the target index if it exists
                if (_targetSearchClient.Indexes.Exists(Settings.TargetSearchIndex))
                {
                    _targetSearchClient.Indexes.Delete(Settings.TargetSearchIndex);
                }

                // the new index - could prob just copy them directly, but may need some tweaks
                List<Microsoft.Azure.Search.Models.Field> fields = new List<Microsoft.Azure.Search.Models.Field>();

                // enumerate legacy and push to target
                foreach (var lfield in legacyIndex.Fields)
                {
                    fields.Add(new Microsoft.Azure.Search.Models.Field() {
                        Name = lfield.Name,
                        Type = lfield.Type,
                        IsKey = lfield.IsKey,
                        IsSearchable = lfield.IsSearchable,
                        IsFilterable = lfield.IsFilterable,
                        IsSortable = lfield.IsSortable,
                        IsFacetable = lfield.IsFacetable,
                        IsRetrievable = lfield.IsRetrievable
                    });
                }

                // the next index
                var index = new Microsoft.Azure.Search.Models.Index(Settings.TargetSearchIndex, fields);

                // create the index
                _targetSearchClient.Indexes.Create(index);

                Console.WriteLine("Successfully copied index!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem creating the index: {0}\r\n", ex.Message.ToString());
            }
        }
 public async Task <Index> CreateAsync(Index index)
 {
     return(await _inner.CreateAsync(index));
 }
        public async Task <IFunctionIndexer <TFunctionMessage> > CreateFunctionIndexer <TFunctionMessage, TSearchDocument>(Index index, Func <FunctionCall <TFunctionMessage>, TSearchDocument> mapperFunc)
            where TFunctionMessage : FunctionMessage, new()
            where TSearchDocument : class, new()
        {
            index = await GetOrCreateAzureIndex(index);

            var mapper = new FunctionMessageToSearchDocumentMapper <TFunctionMessage, TSearchDocument>(mapperFunc);

            return(new AzureFunctionIndexer <TFunctionMessage, TSearchDocument>(index, GetOrCreateIndexClient(index.Name), mapper));
        }
        public async Task <IEventIndexer <TEvent> > CreateEventIndexer <TEvent, TSearchDocument>(Index index, Func <EventLog <TEvent>, TSearchDocument> mappingFunc)
            where TEvent : class
            where TSearchDocument : class, new()
        {
            index = await GetOrCreateAzureIndex(index);

            var mapper = new EventToSearchDocumentMapper <TEvent, TSearchDocument>(mappingFunc);
            IEventIndexer <TEvent> indexer = new AzureEventIndexer <TEvent, TSearchDocument>(index, GetOrCreateIndexClient(index.Name), mapper);

            return(indexer);
        }