Пример #1
0
        public List <SearchResultItem> GetContent(string database, string language, List <ID> templateIds, int take, int skip = 0)
        {
            var templatePredicate = PredicateBuilder.False <SearchResultItem>();

            foreach (var t in templateIds)
            {
                templatePredicate = templatePredicate.Or(x => x.TemplateId == t);
            }

            var index = ContentSearch.GetIndex(ContentSearch.GetSitecoreIndexName(database));

            using (var context = index.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
            {
                var results = context.GetQueryable <SearchResultItem>()
                              .Where(templatePredicate)
                              .Where(a =>
                                     a.Paths.Contains(Settings.ContentNodeId) &&
                                     a.Language == language)
                              .OrderBy(a => a.ItemId)
                              .Skip(skip)
                              .Take(take);

                return(results.ToList());
            }
        }
        public virtual void RebuildCognitiveIndexes()
        {
            List <string> cogIndexes = new List <string>();
            var           nodes      = Sitecore.Configuration.Factory.GetConfigNodes("contentSearch/configuration/indexes/index");

            foreach (XmlNode n in nodes)
            {
                var id = n.Attributes?["id"];
                if (id == null || !id.Value.StartsWith("cognitive"))
                {
                    continue;
                }

                var dbNode = n.SelectSingleNode("locations/crawler/Database");
                var value  = dbNode?.FirstChild?.InnerText;
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                cogIndexes.Add(value);
            }

            foreach (var dbName in cogIndexes)
            {
                var searchIndex = ContentSearch.GetIndex(GetCognitiveIndexName(dbName));
                IndexCustodian.FullRebuild(searchIndex);
            }
        }
        public virtual List <SearchResultItem> GetResults(string query)
        {
            var indexName = ContentSearch.GetSitecoreIndexName("master");
            var index     = ContentSearch.GetIndex(indexName);

            using (var context = index.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
            {
                var contentPredicate = PredicateBuilder.False <SearchResultItem>();

                if (query.Contains(" "))
                {
                    var words = query.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    words.ForEach(w => contentPredicate = contentPredicate
                                                          .Or(item => item.Content.Contains(w)));
                }
                else
                {
                    contentPredicate = contentPredicate.Or(item => item.Content.Contains(query));
                }

                return(context.GetQueryable <SearchResultItem>()
                       .Where(a => a.Paths.Contains(Sitecore.ItemIDs.ContentRoot))
                       .Where(contentPredicate)
                       .Take(10)
                       .ToList());
            }
        }
        protected List <SearchResultItem> GetCurrentUserUnlockedItems(string db)
        {
            var userMod = AuthenticationWrapper.GetCurrentUser().DisplayName.Replace("\\", "").ToLower();

            using (var context = ContentSearchWrapper.GetIndex(ContentSearchWrapper.GetSitecoreIndexName(db)).CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck)) {
                return(context
                       .GetQueryable <SearchResultItem>()
                       .Where(a => a.LockOwner.Equals(userMod)).ToList());
            }
        }
        public override ConversationResponse Respond(LuisResult result, ItemContextParameters parameters, IConversation conversation)
        {
            var message = "";
            var index   = (string)conversation.Data[IndexKey];

            if (index == "All")
            {
                IndexCustodian.RebuildAll(new [] { IndexGroup.Experience });
                message = "All indexes are being rebuilt";
            }
            else
            {
                var searchIndex = ContentSearchWrapper.GetIndex(index);
                IndexCustodian.FullRebuild(searchIndex);
                message = $"The {index} index is being rebuilt";
            }

            return(ConversationResponseFactory.Create(message));
        }
Пример #6
0
        public override ConversationResponse Respond(LuisResult result, ItemContextParameters parameters, IConversation conversation)
        {
            var message = "";
            var index   = (string)conversation.Data[IndexKey];

            if (index == AllOption)
            {
                IndexCustodian.RebuildAll(new [] { IndexGroup.Experience });
                message = Translator.Text("Chat.Intents.RebuildIndex.AllRebuiltMessage");
            }
            else
            {
                var searchIndex = ContentSearchWrapper.GetIndex(index);
                IndexCustodian.FullRebuild(searchIndex);
                message = string.Format(Translator.Text("Chat.Intents.RebuildIndex.RebuildIndexMessage"), index);
            }

            return(ConversationResponseFactory.Create(message));
        }
        public virtual List <SearchResultItem> GetResults(
            string db,
            string language,
            string query,
            Dictionary <string, string> parameters,
            int skip,
            int take)
        {
            var indexName = ContentSearch.GetSitecoreIndexName(db);
            var index     = ContentSearch.GetIndex(indexName);

            using (var context = index.CreateSearchContext(SearchSecurityOptions.EnableSecurityCheck))
            {
                var queryable = context.GetQueryable <SearchResultItem>()
                                .Where(a => a.Language == language && a["_latestversion"] == "1");

                if (parameters.ContainsKey(Constants.SearchParameters.FilterPath))
                {
                    var path = new ID(parameters[Constants.SearchParameters.FilterPath]);
                    queryable = queryable.Where(c => c.Paths.Contains(path));
                }

                if (parameters.ContainsKey(Constants.SearchParameters.TemplateId))
                {
                    var idFilter = new ID(parameters[Constants.SearchParameters.TemplateId]);
                    queryable = queryable.Where(c => c.TemplateId == idFilter);
                }

                if (parameters.ContainsKey(Constants.SearchParameters.TemplateName))
                {
                    var templateName = parameters[Constants.SearchParameters.TemplateName];
                    queryable = queryable.Where(c => c.TemplateName == templateName);
                }

                if (parameters.ContainsKey(Constants.SearchParameters.FieldName) &&
                    parameters.ContainsKey(Constants.SearchParameters.FieldValue))
                {
                    var fieldName  = parameters[Constants.SearchParameters.FieldName];
                    var fieldValue = parameters[Constants.SearchParameters.FieldValue];
                    queryable = queryable.Where(c => c[fieldName] == fieldValue);
                }

                if (parameters.ContainsKey(Constants.SearchParameters.ItemName))
                {
                    var itemName = parameters[Constants.SearchParameters.ItemName];
                    queryable = queryable.Where(c => c.Name == itemName);
                }

                var contentPredicate = PredicateBuilder.False <SearchResultItem>();
                var notEmptyQuery    = !string.IsNullOrWhiteSpace(query);
                if (notEmptyQuery)
                {
                    contentPredicate = contentPredicate
                                       .Or(item => item.Name.Contains(query).Boost(10) ||
                                           item.Content.Contains(query).Boost(5));
                }
                else
                {
                    contentPredicate = contentPredicate
                                       .Or(item => item.Content.Contains(query));
                }

                queryable = queryable
                            .Where(contentPredicate)
                            .Skip(skip);

                if (take > 0)
                {
                    queryable = queryable.Take(take);
                }

                return(queryable.ToList());
            }
        }