public void AddIndex(ISearchIndex index) { Assert.ArgumentNotNull(index, "index"); Assert.IsFalse((this.Indexes.ContainsKey(index.Name) ? 1 : 0) != 0, "An index with the name \"{0}\" have already been added.", index.Name); this.Indexes[index.Name] = index; if (index.Configuration == null) { XmlNode configNode = this.factory.GetConfigNode(this.DefaultIndexConfigurationPath); if (configNode == null) { throw new ConfigurationException("Index must have a ProviderIndexConfiguration associated with it. Please check your config."); } ProviderIndexConfiguration @object = this.factory.CreateObject <ProviderIndexConfiguration>(configNode); if (@object == null) { throw new ConfigurationException("Unable to create configuration object from path specified in setting 'ContentSearch.DefaultIndexConfigurationPath'. Please check your config."); } index.Configuration = @object; } if (!index.Configuration.InitializeOnAdd) { return; } index.Initialize(); }
public IEnumerable <Suggestion> GetSuggestions(SuggesterModel model, out XA.Foundation.Search.Timer queryTimer, out string indexName) { bool fuzzy = Configuration.Settings.GetBoolSetting("AzureSearchSuggesterFuzzy", false); bool highlights = Configuration.Settings.GetBoolSetting("AzureSearchSuggesterHighlight", false); ISearchIndex searchIndex = IndexResolver.ResolveIndex(!model.ContextItemID.IsNull ? ContentRepository.GetItem(model.ContextItemID) : null); indexName = searchIndex.Name; searchIndex.Initialize(); using (IProviderSearchContext searchContext = searchIndex.CreateSearchContext(SearchSecurityOptions.Default)) { SuggestParameters sp = new SuggestParameters() { UseFuzzyMatching = fuzzy, Top = 5 }; if (highlights) { string tag = Configuration.Settings.GetSetting("AzureSearchSuggesterHighlightTag"); sp.HighlightPreTag = $"<{tag}>"; sp.HighlightPostTag = $"</{tag}>"; } AzureSuggestQuery term = model.Term; DocumentSuggestResult <Document> handlerQueryResults; using (queryTimer = new XA.Foundation.Search.Timer()) handlerQueryResults = searchContext.Suggest(term, Configuration.Settings.GetSetting("AzureSearchSuggesterName"), sp); return(handlerQueryResults.Results.Select(a => new Suggestion() { Term = a.Text, Payload = JsonConvert.SerializeObject(a.Document) })); } }
public virtual void AddIndex(ISearchIndex index) { Assert.ArgumentNotNull(index, "index"); Indexes[index.Name] = index; if (DefaultIndexConfiguration == null) { return; } if (index.Configuration == null) { index.Configuration = DefaultIndexConfiguration; } else { var defaultIndexConfiguration = DefaultIndexConfiguration as ElasticSearchIndexConfiguration; var configuration = index.Configuration as ElasticSearchIndexConfiguration; if (defaultIndexConfiguration != null && configuration != null) { configuration.MergeConfiguration(defaultIndexConfiguration); } } index.Initialize(); }
public async Task <Unit> Handle(RebuildSearchIndex request, CancellationToken cancellationToken) { bool indexFolderExists = Directory.Exists(FileSystemLayout.SearchIndexFolder); await _searchIndex.Initialize(_localFileSystem); if (!indexFolderExists || await _configElementRepository.GetValue <int>(ConfigElementKey.SearchIndexVersion) < _searchIndex.Version) { _logger.LogInformation("Migrating search index to version {Version}", _searchIndex.Version); List <int> itemIds = await _searchRepository.GetItemIdsToIndex(); await _searchIndex.Rebuild(_searchRepository, itemIds); await _configElementRepository.Upsert(ConfigElementKey.SearchIndexVersion, _searchIndex.Version); _logger.LogInformation("Done migrating search index"); } else { _logger.LogInformation("Search index is already version {Version}", _searchIndex.Version); } return(Unit.Default); }
public virtual void AddIndex(ISearchIndex index) { this.Indexes[index.Name] = index; index.Configuration = this.DefaultIndexConfiguration; index.Initialize(); }
public void AddIndex(ISearchIndex index) { Assert.ArgumentNotNull(index, "index"); Assert.IsFalse((this.Indexes.ContainsKey(index.Name) ? 1 : 0) != 0, "An index with the name \"{0}\" have already been added.", index.Name); this.Indexes[index.Name] = index; if (index.Configuration == null) { XmlNode configNode = this.factory.GetConfigNode(this.DefaultIndexConfigurationPath); if (configNode == null) throw new ConfigurationException("Index must have a ProviderIndexConfiguration associated with it. Please check your config."); var config = this.factory.CreateObject<ProviderIndexConfiguration>(configNode); if (config == null) throw new ConfigurationException("Unable to create configuration object from path specified in setting 'ContentSearch.AzureDefaultIndexConfigurationPath'. Please check your config."); index.Configuration = config; } if (!index.Configuration.InitializeOnAdd) return; index.Initialize(); }