示例#1
0
        public ActionResult RemoveSynonym(string language, string term)
        {
            if (string.IsNullOrWhiteSpace(term))
            {
                throw new Exception($"RemoveSynonym: {nameof(term)} cannot be blank");
            }

            var client = VulcanHandler.GetClient(string.IsNullOrWhiteSpace(language) ? CultureInfo.InvariantCulture : new CultureInfo(language));

            client.RemoveSynonym(term);

            return(Json("OK"));
        }
示例#2
0
        public ActionResult AddSynonym(string language, string term, string synonyms, bool biDirectional)
        {
            if (string.IsNullOrWhiteSpace(term))
            {
                throw new Exception($"AddSynonym: {nameof(term)} cannot be blank");
            }

            if (string.IsNullOrWhiteSpace(synonyms))
            {
                throw new Exception($"AddSynonym: {nameof(synonyms)} cannot be blank");
            }

            var client = VulcanHandler.GetClient(string.IsNullOrWhiteSpace(language) ? CultureInfo.InvariantCulture : new CultureInfo(language));

            client.AddSynonym(term, synonyms.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries), biDirectional);

            return(Json("OK"));
        }
示例#3
0
        public ActionResult ListSynonyms(string language)
        {
            var client = VulcanHandler.GetClient(string.IsNullOrWhiteSpace(language) ? CultureInfo.InvariantCulture : new CultureInfo(language));

            return(Json(client.GetSynonyms(), JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public ActionResult Index()
        {
            var clients = VulcanHandler.GetClients()?.OrderBy(x => x.Language.EnglishName).ToList();

            var viewModel = new HomeViewModel
            {
                VulcanClients        = clients,
                VulcanHandler        = VulcanHandler,
                PocoIndexers         = _vulcanIndexers.OfType <IVulcanPocoIndexer>(),
                VulcanIndexModifiers = _vulcanIndexModifiers,
                ProtectedUiPath      = EPiServer.Shell.Paths.ProtectedRootPath
            };

            // ReSharper disable once InvertIf
            if (clients?.Any() == true)
            {
                var healthResponse = clients[0].CatIndices();

                viewModel.IndexHealthDescriptor.AddRange(healthResponse.Records.Where(r => r.Index.StartsWith(VulcanHandler.Index)));

                // doc types count
                var typeCounts = new Dictionary <string, Tuple <long, string, List <string> > >();

                foreach (var client in clients)
                {
                    var uiDisplayName = client.Language.Equals(CultureInfo.InvariantCulture) ?
                                        "non-specific" :
                                        $"{client.Language.EnglishName} ({client.Language.Name})";

                    //search can error in some situations
                    Nest.BucketAggregate typeCount;

                    try
                    {
                        typeCount = client.Search <object>(m => m.AllTypes()
                                                           .SearchType(SearchType.DfsQueryThenFetch). // possible 5x to 2x difference
                                                           Aggregations(aggs => aggs.Terms("typeCount", t => t.Field("_type"))))
                                    .Aggregations["typeCount"] as Nest.BucketAggregate;
                    }
                    catch
                    {
                        typeCount = null;
                    }

                    var  docCounts = new List <string>();
                    long total     = 0;
#if NEST2
                    var buckets = typeCount?.Items.OfType <Nest.KeyedBucket>() ?? new List <Nest.KeyedBucket>();

                    foreach (var type in buckets)
                    {
                        total += type.DocCount ?? 0;
                        docCounts.Add($"{type.Key}({type.DocCount})");
                    }
#elif NEST5
                    var buckets = typeCount?.Items.OfType <Nest.KeyedBucket <object> >() ?? new List <Nest.KeyedBucket <object> >();

                    foreach (var type in buckets)
                    {
                        total += type.DocCount ?? 0;
                        docCounts.Add($"{type.Key}({type.DocCount})");
                    }
#endif

                    typeCounts[client.IndexName] = Tuple.Create(total, uiDisplayName, docCounts);
                }

                viewModel.ClientViewInfo = typeCounts;
            }

            return(View(Helper.ResolveView("Home/Index.cshtml"), viewModel));
        }