public ActionResult Index() { var model = new BestBetsViewModel(CurrentLanguage); foreach (KeyValuePair <string, string> language in Languages) { var name = language.Value; name = String.Concat(name.Substring(0, 1).ToUpper(), name.Substring(1)); var indexName = SwapLanguage(CurrentIndex, language.Key); model.BestBetsByLanguage.Add(new BestBetsByLanguage { LanguageName = name, LanguageId = language.Key, Indices = UniqueIndices, BestBets = GetBestBetsForLanguage(language.Key, indexName) }); } var config = ElasticSearchSection.GetConfiguration(); foreach (ContentSelectorConfiguration entry in config.ContentSelector) { model.SelectorTypes.Add(entry.Type.ToLower()); model.SelectorRoots.Add(new ContentReference(entry.Id, entry.Provider)); } var currentType = config.IndicesParsed.FirstOrDefault(i => CurrentIndex.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase))?.Type; ViewBag.TypeName = !String.IsNullOrEmpty(currentType) ? Type.GetType(currentType)?.AssemblyQualifiedName : typeof(IndexItem).AssemblyQualifiedName; return(View("~/Views/ElasticSearchAdmin/BestBets/Index.cshtml", model)); }
internal static void SetupBestBets() { BestBets = new ConcurrentDictionary <string, List <BestBet> >(); var repository = ServiceLocator.Current.GetInstance <IBestBetsRepository>(); var settings = ServiceLocator.Current.GetInstance <IElasticSearchSettings>(); var languageBranchRepository = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>(); var languageIds = languageBranchRepository.ListEnabled() .Select(lang => lang.LanguageID); var config = ElasticSearchSection.GetConfiguration(); var indexList = config.IndicesParsed.Select(i => i.Name).ToList(); if (settings.CommerceEnabled) { indexList.Add($"{settings.Index}-{Constants.CommerceProviderName}".ToLower()); } foreach (var index in indexList) { Logger.Information($"Setup BestBets for index '{index}'"); foreach (var languageId in languageIds) { Logger.Information($"Language '{languageId}'"); var indexName = index + "-" + languageId; var bestBets = repository.GetBestBets(languageId, indexName).ToList(); BestBets.TryAdd(indexName, bestBets); Logger.Information($"BestBets:\n{String.Join("\n", bestBets.Select(b => b.Phrase + " => " + b.Id))}"); } } }
public virtual ActionResult AddNewIndexWithMappings() { if (_serverInfoService.GetInfo().Version < Constants.MinimumSupportedVersion) { throw new InvalidOperationException("Elasticsearch version 5 or higher required"); } ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); foreach (KeyValuePair <string, string> lang in Languages) { foreach (IndexConfiguration indexConfig in config.IndicesParsed) { Type indexType = GetIndexType(indexConfig, config); var indexName = _settings.GetCustomIndexName(indexConfig.Name, lang.Key); Index index = CreateIndex(indexType, indexName); if (IsCustomType(indexType)) { _coreIndexer.UpdateMapping(indexType, indexType, indexName, lang.Key, optIn: false); } else { UpdateMappingForTypes(ContentReference.RootPage, indexType, indexName, lang.Key); } index.WaitForStatus(); } } return(RedirectToAction("Index")); }
private List <IndexInformation> GetIndices() { var indexHelper = new Admin.Index(_settings, _httpClientHelper, "GetIndices-NA"); var indices = indexHelper.GetIndices().ToList(); var config = ElasticSearchSection.GetConfiguration(); foreach (var indexInfo in indices) { var parsed = config.IndicesParsed .OrderByDescending(i => i.Name.Length) .FirstOrDefault(i => indexInfo.Index.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase)); indexInfo.Type = String.IsNullOrWhiteSpace(parsed?.Type) ? "[default]" : Type.GetType(parsed.Type)?.Name; var displayName = new StringBuilder(parsed?.DisplayName); if (indexInfo.Index.Contains($"-{Constants.CommerceProviderName}".ToLowerInvariant())) { displayName.Append(" Commerce"); } indexInfo.DisplayName = displayName.ToString(); } return(indices); }
public ActionResult Index() { HealthInformation clusterHealth = _healthHelper.GetClusterHealth(); Node[] nodeInfo = _healthHelper.GetNodeInfo(); var indexHelper = new Index(_settings); var allIndices = indexHelper.GetIndices(); ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); foreach (var index in allIndices) { var parsed = config.IndicesParsed.FirstOrDefault(i => index.Index.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase)); index.Type = String.IsNullOrWhiteSpace(parsed?.Type) ? "[default]" : Type.GetType(parsed.Type)?.Name; } var adminViewModel = new AdminViewModel(clusterHealth, allIndices.OrderBy(i => i.Type), nodeInfo); return(View("~/Views/ElasticSearchAdmin/Admin/Index.cshtml", adminViewModel)); }
public ActionResult Index(string index = null, string languageId = null) { var languages = _languageBranchRepository.ListEnabled() .Select(lang => new { lang.LanguageID, lang.Name }) .ToArray(); var indices = _indexHelper.GetIndices() .Select(i => i.Index).ToList(); if (String.IsNullOrWhiteSpace(index) || !indices.Contains(index)) { index = indices.FirstOrDefault(); } ViewBag.Indices = indices.Count > 1 ? indices : null; ViewBag.SelectedIndex = index; if (languageId != null) { CurrentLanguage = languageId; } var model = new BestBetsViewModel(CurrentLanguage); foreach (var language in languages) { var name = language.Name; name = String.Concat(name.Substring(0, 1).ToUpper(), name.Substring(1)); model.BestBetsByLanguage.Add(new BestBetsByLanguage { LanguageName = name, LanguageId = language.LanguageID, BestBets = GetBestBetsForLanguage(language.LanguageID, index) }); } var config = ElasticSearchSection.GetConfiguration(); foreach (ContentSelectorConfiguration entry in config.ContentSelector) { model.SelectorTypes.Add(entry.Type.ToLower()); model.SelectorRoots.Add(new ContentReference(entry.Id, entry.Provider)); } var currentType = config.IndicesParsed.FirstOrDefault(i => index.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase))?.Type; if (!String.IsNullOrEmpty(currentType)) { ViewBag.TypeName = Type.GetType(currentType).AssemblyQualifiedName; } else { ViewBag.TypeName = typeof(IndexItem).AssemblyQualifiedName; } return(View("~/Views/ElasticSearchAdmin/BestBets/Index.cshtml", model)); }
static TrackingRepository() { var config = ElasticSearchSection.GetConfiguration(); string connectionStringName = String.IsNullOrWhiteSpace(config.TrackingConnectionStringName) ? "EPiServerDB" : config.TrackingConnectionStringName; ConnectionString = ConfigurationManager.ConnectionStrings?[connectionStringName]?.ConnectionString; }
private static string GetConnectionString() { var config = ElasticSearchSection.GetConfiguration(); var connectionStringName = String.IsNullOrWhiteSpace(config.TrackingConnectionStringName) ? "EPiServerDB" : config.TrackingConnectionStringName; return(ConfigurationManager.ConnectionStrings?[connectionStringName]?.ConnectionString); }
private string[] GetMappedFields(string indexName, string language) { var config = ElasticSearchSection.GetConfiguration(); var nameWithoutLanguage = indexName.Substring(0, indexName.Length - language.Length - 1); var index = config.IndicesParsed.Single(i => i.Name == nameWithoutLanguage); var mappingType = String.IsNullOrEmpty(index.Type) ? typeof(IndexItem) : Type.GetType(index.Type); var mapping = _mapping.GetIndexMapping(mappingType, language, indexName); return(mapping.Properties.Select(p => p.Key).ToArray()); }
protected string GetTypeName() { var config = ElasticSearchSection.GetConfiguration(); var currentType = config.IndicesParsed.FirstOrDefault(i => CurrentIndex.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase))?.Type; return(!String.IsNullOrEmpty(currentType) ? Type.GetType(currentType)?.AssemblyQualifiedName : typeof(IndexItem).AssemblyQualifiedName); }
public ActionResult AddNewIndex() { if (Core.Server.Info.Version.Major < 5) { throw new Exception("Elasticsearch version 5 or higher required"); } ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); IEnumerable <string> languages = _languageBranchRepository .ListEnabled() .Select(lang => lang.LanguageID); foreach (string lang in languages) { foreach (IndexConfiguration indexConfig in config.IndicesParsed) { var indexName = _settings.GetCustomIndexName(indexConfig.Name, lang); Type indexType = GetIndexType(indexConfig, config); var index = new Index(_settings, indexName); if (!index.Exists) { index.Initialize(indexType); index.WaitForStatus(); index.DisableDynamicMapping(indexType); index.WaitForStatus(); } if (IsCustomType(indexType)) { _coreIndexer.UpdateMapping(indexType, indexType, indexName, lang, true); index.WaitForStatus(); } else if (_settings.CommerceEnabled) { indexName = _settings.GetCustomIndexName($"{indexConfig.Name}-{Constants.CommerceProviderName}", lang); index = new Index(_settings, indexName); if (!index.Exists) { index.Initialize(indexType); index.WaitForStatus(); index.DisableDynamicMapping(indexType); index.WaitForStatus(); } } } } return(RedirectToAction("Index")); }
public ElasticsearchSectionTests() { var mockSection = new Mock <ElasticSearchSection>(); mockSection .SetupGet(m => m.Indices) .Returns(new IndicesCollection()); mockSection .SetupGet(m => m.Files) .Returns(new FilesCollection()); _section = mockSection.Object; }
private void CreateAnalyzerSettings() { var config = ElasticSearchSection.GetConfiguration(); var indexConfig = config.IndicesParsed.FirstOrDefault(i => i.Name == _nameWithoutLanguage); string json = Serialization.Serialize(Analyzers.GetAnalyzerSettings(_language, indexConfig?.SynonymsFile)); var data = Encoding.UTF8.GetBytes(json); var uri = _indexing.GetUri(_name, "_settings"); Logger.Information($"Creating analyzer settings. Language: {_name}"); Logger.Information(JToken.Parse(json).ToString(Formatting.Indented)); _httpClientHelper.Put(uri, data); }
private static Type GetIndexType(IndexConfiguration index, ElasticSearchSection config) { if (index.Default || config.IndicesParsed.Count() == 1) { return(typeof(IndexItem)); } if (String.IsNullOrWhiteSpace(index.Type)) { return(null); } return(Type.GetType(index.Type, false, true)); }
/// <summary> /// Include the specified file-extension in the index /// </summary> /// <param name="extension">The extension, e.g. pdf, doc, xls</param> /// <returns>The <see cref="Indexing"/> instance</returns> public Indexing IncludeFileType(string extension) { ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); if (!config.Files.Enabled) { Logger.Information($"Not adding '{extension}', file indexing is disabled"); return(this); } if (!String.IsNullOrWhiteSpace(extension)) { Extensions.Add(extension.Trim(' ', '.').ToLower()); } return(this); }
private static IEnumerable <string> GetFileExtensions() { ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); if (!config.Files.Enabled) { Logger.Information("File indexing disabled"); yield break; } Logger.Information($"Adding allowed file extensions from config. Max size is {config.Files.ParsedMaxsize}"); foreach (FileConfiguration file in config.Files) { Logger.Information($"Found: {file.Extension}"); yield return(file.Extension); } }
internal static void SetupBestBets() { BestBets.Clear(); var repository = ServiceLocator.Current?.GetInstance <IBestBetsRepository>(); var settings = ServiceLocator.Current?.GetInstance <IElasticSearchSettings>(); var languageBranchRepository = ServiceLocator.Current?.GetInstance <ILanguageBranchRepository>(); if (repository == null || settings == null || languageBranchRepository == null) { // Probably in test-context return; } var languageIds = languageBranchRepository.ListEnabled() .Select(lang => lang.LanguageID); var config = ElasticSearchSection.GetConfiguration(); var indexList = config.IndicesParsed.ToList(); if (settings.CommerceEnabled) { indexList.Add(new IndexConfiguration { Name = $"{settings.Index}-{Constants.CommerceProviderName}".ToLower(), DisplayName = "Commerce" }); } foreach (IndexConfiguration index in indexList) { Logger.Information($"Setup BestBets for index '{index.Name}'"); foreach (var languageId in languageIds) { Logger.Information($"Language '{languageId}'"); var indexName = index.Name + "-" + languageId; var bestBets = repository.GetBestBets(languageId, indexName).ToList(); BestBets.TryAdd(indexName, bestBets); Logger.Information($"BestBets:\n{System.String.Join("\n", bestBets.Select(b => b.Phrase + " => " + b.Id))}"); } } }
public ActionResult AddNewIndex() { if (Core.Server.Info.Version.Major < 5) { throw new InvalidOperationException("Elasticsearch version 5 or higher required"); } var config = ElasticSearchSection.GetConfiguration(); foreach (var lang in Languages) { foreach (IndexConfiguration indexConfig in config.IndicesParsed) { var indexName = _settings.GetCustomIndexName(indexConfig.Name, lang.Key); Type indexType = GetIndexType(indexConfig, config); var index = new Index(_settings, _httpClientHelper, indexName); if (!index.Exists) { index.Initialize(indexType); } if (IsCustomType(indexType)) { _coreIndexer.UpdateMapping(indexType, indexType, indexName, lang.Key, false); index.WaitForStatus(); } else if (_settings.CommerceEnabled) { CreateCommerceIndex(lang.Key, indexConfig, indexType); } else { index.WaitForStatus(); index.DisableDynamicMapping(indexType); index.WaitForStatus(); } } } return(RedirectToAction("Index")); }
public virtual ActionResult AddNewIndex() { if (_serverInfoService.GetInfo().Version < Constants.MinimumSupportedVersion) { throw new InvalidOperationException("Elasticsearch version 5 or higher required"); } ElasticSearchSection config = ElasticSearchSection.GetConfiguration(); foreach (KeyValuePair <string, string> lang in Languages) { foreach (IndexConfiguration indexConfig in config.IndicesParsed) { Type indexType = GetIndexType(indexConfig, config); var indexName = _settings.GetCustomIndexName(indexConfig.Name, lang.Key); CreateIndex(indexType, indexName); } } return(RedirectToAction("Index")); }
public ElasticSearchSettings() { _configuration = ElasticSearchSection.GetConfiguration(); }