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);
        }
        private ActionResult GetJsonFromEndpoint(string index, string endpoint)
        {
            if (String.IsNullOrWhiteSpace(index))
            {
                index = CurrentIndex;
            }

            var indexHelper = new Admin.Index(_settings, _httpClientHelper, index);

            var indices = indexHelper.GetIndices()
                          .Select(i => i.Index).ToList();

            ViewBag.Indices  = indices;
            ViewBag.Endpoint = endpoint;

            if (!indices.Contains(index))
            {
                return(View("~/Views/ElasticSearchAdmin/Console/_JsonDump.cshtml"));
            }

            ViewBag.SelectedIndex = index;

            string uri      = $"{_settings.Host}/{index}/_{endpoint}";
            string response = _httpClientHelper.GetJson(new Uri(uri));

            ViewBag.Result = JToken.Parse(response).ToString(Formatting.Indented);

            return(View("~/Views/ElasticSearchAdmin/Console/_JsonDump.cshtml"));
        }
Example #3
0
        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));
        }
Example #4
0
        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 SynonymsViewModel(CurrentLanguage);

            foreach (var language in languages)
            {
                var name = language.Name;
                name = String.Concat(name.Substring(0, 1).ToUpper(), name.Substring(1));

                model.SynonymsByLanguage.Add(new LanguageSynonyms
                {
                    Analyzer     = Language.GetLanguageAnalyzer(language.LanguageID),
                    LanguageName = name,
                    LanguageId   = language.LanguageID,
                    Synonyms     = _synonymRepository.GetSynonyms(language.LanguageID, index)
                                   .Select(s =>
                    {
                        var key = s.From;
                        if (key.Contains("=>"))
                        {
                            key = key.Split(new[] { "=>" }, StringSplitOptions.None)[0].Trim();
                        }

                        return(new Synonym {
                            From = key, To = s.To, TwoWay = s.TwoWay
                        });
                    })
                                   .ToList()
                });
            }

            return(View("~/Views/ElasticSearchAdmin/Synonyms/Index.cshtml", model));
        }
        public ActionResult Index(string query, string index)
        {
            if (String.IsNullOrWhiteSpace(index))
            {
                index = CurrentIndex;
            }

            var indexHelper = new Admin.Index(_settings, _httpClientHelper, index);

            List <string> indices = indexHelper.GetIndices()
                                    .Select(i => i.Index).ToList();

            if (!indices.Contains(index))
            {
                index = CurrentIndex;
            }

            ViewBag.Indices       = indices;
            ViewBag.SelectedIndex = index;

            if (String.IsNullOrWhiteSpace(query))
            {
                query = "{\n    \"size\" : 10,\n    \"query\" : {\n        \"match_all\" : {}\n    }\n}";
            }

            ViewBag.Query = query;

            if (String.IsNullOrWhiteSpace(index) || !indices.Contains(index))
            {
                return(View("~/Views/ElasticSearchAdmin/Console/Index.cshtml"));
            }

            string uri = $"{_settings.Host}/{index}/_search";

            if (Core.Server.Info.Version.Major >= 7)
            {
                uri += "?rest_total_hits_as_int=true";
            }

            byte[] data       = Encoding.UTF8.GetBytes(query);
            byte[] returnData = _httpClientHelper.Post(new Uri(uri), data);
            string response   = Encoding.UTF8.GetString(returnData);

            ViewBag.Result = JToken.Parse(response).ToString(Formatting.Indented);

            return(View("~/Views/ElasticSearchAdmin/Console/Index.cshtml"));
        }
        public ActionResult Index(string languageId = null, string index = 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;

            TrackingViewModel model = new TrackingViewModel(languageId);

            foreach (var language in languages)
            {
                var name = language.Name;
                name = String.Concat(name.Substring(0, 1).ToUpper(), name.Substring(1));

                model.SearchesByLanguage.Add(new TrackingByLanguage
                {
                    LanguageName = name,
                    LanguageId   = language.LanguageID,
                    Searches     = _trackingRepository
                                   .GetSearches(language.LanguageID, index)
                                   .OrderByDescending(kvp => kvp.Searches)
                                   .ToDictionary(d => d.Query, d => d.Searches)
                });

                model.SearchesWithoutHitsByLanguage.Add(new TrackingByLanguage
                {
                    LanguageName = name,
                    LanguageId   = language.LanguageID,
                    Searches     = _trackingRepository
                                   .GetSearchesWithoutHits(language.LanguageID, index)
                                   .OrderByDescending(kvp => kvp.Searches)
                                   .ToDictionary(d => d.Query, d => d.Searches)
                });
            }

            return(View("~/Views/ElasticSearchAdmin/Tracking/Index.cshtml", model));
        }