Пример #1
0
            /// <summary>
            /// Remotes the build.
            /// </summary>
            protected void RemoteBuild()
            {
                Job job = Context.Job;

                if (job != null)
                {
                    try
                    {
                        // Copy PsExec to Target Address
                        foreach (string str in this.indexNames)
                        {
                            if (str.EndsWith("_remote"))
                            {
                                var index = RemoteSearchManager.GetIndex(str) as RemoteIndex;
                                if (index != null)
                                {
                                    index.Rebuild();
                                }

                                JobStatus status = job.Status;
                                status.Processed += 1L;
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        job.Status.Failed = true;
                        job.Status.Messages.Add(exception.ToString());
                    }

                    job.Status.State = JobState.Finished;
                }
            }
Пример #2
0
        /// <summary>
        /// This is the process that Runs the Index Rebuild
        /// </summary>
        private void BuildIndexes()
        {
            var selected = new ListString(Registry.GetString("/Current_User/Rebuild Search Index/Selected"));
            var indexMap = new ListString();

            foreach (Index str3 in SearchManager.Indexes)
            {
                this.BuildIndexCheckbox(str3.Name, str3.Name, selected, indexMap);
            }

            if (Config.Scaling.Enabled)
            {
                RemoteSearchManager.Initialize();
                foreach (RemoteIndex str3 in RemoteSearchManager.Indexes)
                {
                    this.BuildIndexCheckbox(str3.Name, str3.Name, selected, indexMap);
                }

                InMemorySearchManager.Initialize();
                foreach (InMemoryIndex str3 in InMemorySearchManager.Indexes)
                {
                    this.BuildIndexCheckbox(str3.Name, str3.Name, selected, indexMap);
                }
            }

            this.BuildIndexCheckbox("$system", "Quick search index", selected, indexMap);
            this.IndexMap = indexMap.ToString();
        }
        public string Build(string indexName, string returnPath)
        {
            var index = RemoteSearchManager.GetIndex(indexName) as RemoteIndex;

            if (index != null)
            {
                index.SilentRebuild();
            }
            var indexLocalFolder = Settings.IndexFolder.Replace("/", "");

            WebServiceCall();
            Copy((Path.Combine(Config.RemoteIndexLocation, indexName)), indexLocalFolder + "\\" + indexName);
            WebServiceCallEnable();
            return("Done");
        }
        /// <summary>
        /// Given an Item, this will return the name of the Index that it will use to search on
        /// </summary>
        /// <returns>The Name of the Index</returns>
        /// <param name="item">The item which will be used to determine (based off the item path) which index will be used for the search</param>
        public static string GetContextIndex(Item item)
        {
            Contract.Requires(item.IsNotNull());

            if (item.IsNotNull())
            {
                RemoteSearchManager.Initialize();
                foreach (var index in from index in RemoteSearchManager.Indexes
                         let indexConfigurationNode =
                             Configuration.Factory.GetConfigNode(
                                 "/sitecore/search/remoteconfiguration/indexes/index[@id='" + (index as RemoteIndex).Name +
                                 "']/locations/ItemBucketSearch/Root")
                             where indexConfigurationNode != null
                             where item.Paths.FullPath.StartsWith(indexConfigurationNode.InnerText)
                             select index)
                {
                    return((index as RemoteIndex).Name);
                }

                InMemorySearchManager.Initialize();
                foreach (var index in from index in InMemorySearchManager.Indexes
                         let indexConfigurationNode =
                             Configuration.Factory.GetConfigNode(
                                 "/sitecore/search/inmemoryconfiguration/indexes/index[@id='" + (index as InMemoryIndex).Name +
                                 "']/locations/ItemBucketSearch/Root")
                             where indexConfigurationNode != null
                             where item.Paths.FullPath.StartsWith(indexConfigurationNode.InnerText)
                             select index)
                {
                    return((index as InMemoryIndex).Name);
                }

                foreach (var index in from index in Sitecore.Search.SearchManager.Indexes
                         let indexConfigurationNode =
                             Configuration.Factory.GetConfigNode(
                                 "/sitecore/search/configuration/indexes/index[@id='" + index.Name +
                                 "']/locations/ItemBucketSearch/Root")
                             where indexConfigurationNode != null
                             where item.Paths.FullPath.StartsWith(indexConfigurationNode.InnerText)
                             select index)
                {
                    return(index.Name);
                }
            }

            return("itembuckets_buckets");
        }
        public static BooleanQuery ContructQuery(DateRangeSearchParam param)
        {
            var indexName = BucketManager.GetContextIndex(Context.ContentDatabase.GetItem(param.LocationIds));

            if (indexName.EndsWith("_remote"))
            {
                Index = RemoteSearchManager.GetIndex(indexName) as RemoteIndex;
            }
            else if (indexName.EndsWith("_inmemory"))
            {
                Index = InMemorySearchManager.GetIndex(indexName) as InMemoryIndex;
            }
            else
            {
                Index = SearchManager.GetIndex(indexName) as Index;
            }
            if (Index.IsNotNull())
            {
                var globalQuery   = new CombinedQuery();
                var fullTextQuery = param.FullTextQuery; // .TrimStart('*').TrimEnd('*') + "*";
                SearcherMethods.ApplyLanguageClause(globalQuery, param.Language);
                if (!string.IsNullOrWhiteSpace(fullTextQuery))
                {
                    if (!fullTextQuery.StartsWith("*"))
                    {
                        SearcherMethods.ApplyFullTextClause(globalQuery, fullTextQuery, indexName);
                    }
                }

                SearcherMethods.ApplyRelationFilter(globalQuery, param.RelatedIds);
                SearcherMethods.ApplyTemplateFilter(globalQuery, param.TemplateIds);
                SearcherMethods.ApplyTemplateNotFilter(globalQuery);
                SearcherMethods.ApplyIDFilter(globalQuery, param.ID);
                SearcherMethods.ApplyLocationFilter(globalQuery, param.LocationIds);
                SearcherMethods.ApplyRefinements(globalQuery, param.Refinements, QueryOccurance.Should);
                SearcherMethods.ApplyLatestVersion(globalQuery);

                if (Config.ExcludeContextItemFromResult)
                {
                    SearcherMethods.ApplyContextItemRemoval(globalQuery, param.LocationIds);
                }

                var translator     = new QueryTranslator(Index);
                var booleanQuery   = translator.ConvertCombinedQuery(globalQuery);
                var innerOccurance = translator.GetOccur(param.Occurance);

                if (!string.IsNullOrWhiteSpace(fullTextQuery))
                {
                    if (fullTextQuery.StartsWith("*"))
                    {
                        SearcherMethods.ApplyFullTextClause(booleanQuery, fullTextQuery, indexName);
                    }
                }

                SearcherMethods.ApplyAuthor(booleanQuery, param.Author);
                SearcherMethods.ApplyDateRangeSearchParam(booleanQuery, param, innerOccurance);
                if (Config.EnableBucketDebug || Constants.EnableTemporaryBucketDebug)
                {
                    Log.Info("Search Clauses Number: " + booleanQuery.Clauses().Count, booleanQuery);
                }

                return(booleanQuery);
            }

            return(null);
        }
        internal virtual KeyValuePair <int, List <SitecoreItem> > GetItems(DateRangeSearchParam param)
        {
            var db = Context.ContentDatabase ?? Sitecore.Context.Database;

            if (db != null)
            {
                var indexName = Util.Constants.Index.Name;
                var item      = db.GetItem(param.LocationIds);
                indexName = BucketManager.GetContextIndex(item.IsNotNull() ? item : db.GetItem(Sitecore.ItemIDs.RootID));

                if (indexName.EndsWith("_remote"))
                {
                    Index = RemoteSearchManager.GetIndex(indexName) as RemoteIndex;
                }
                else if (indexName.EndsWith("_inmemory"))
                {
                    Index = InMemorySearchManager.GetIndex(indexName) as InMemoryIndex;
                }
                else
                {
                    Index = SearchManager.GetIndex(indexName) as Index;
                }

                if (Index.IsNotNull())
                {
                    var globalQuery = new CombinedQuery();
                    SearcherMethods.ApplyLanguageClause(globalQuery, param.Language);
                    if (!string.IsNullOrWhiteSpace(param.FullTextQuery))
                    {
                        if (!param.FullTextQuery.StartsWith("*"))
                        {
                            if (param.FullTextQuery != "*All*" && param.FullTextQuery != "*" && param.FullTextQuery != "**")
                            {
                                SearcherMethods.ApplyFullTextClause(globalQuery, param.FullTextQuery, indexName);
                            }
                        }
                    }

                    SearcherMethods.ApplyRelationFilter(globalQuery, param.RelatedIds);
                    SearcherMethods.ApplyTemplateFilter(globalQuery, param.TemplateIds);
                    SearcherMethods.ApplyTemplateNotFilter(globalQuery);
                    SearcherMethods.ApplyIDFilter(globalQuery, param.ID);
                    if (param.LocationIds.Contains("|"))
                    {
                        SearcherMethods.ApplyCombinedLocationFilter(globalQuery, param.LocationIds);
                    }
                    else
                    {
                        SearcherMethods.ApplyLocationFilter(globalQuery, param.LocationIds);
                    }
                    if (!param.Refinements.ContainsKey("__workflow state")) //Hack!!!!!
                    {
                        SearcherMethods.ApplyRefinements(globalQuery, param.Refinements, QueryOccurance.Should);
                    }
                    SearcherMethods.ApplyLatestVersion(globalQuery);

                    if (Config.ExcludeContextItemFromResult)
                    {
                        SearcherMethods.ApplyContextItemRemoval(globalQuery, param.LocationIds);
                    }

                    var translator     = new QueryTranslator(Index);
                    var booleanQuery   = translator.ConvertCombinedQuery(globalQuery);
                    var innerOccurance = translator.GetOccur(param.Occurance);

                    if (!string.IsNullOrWhiteSpace(param.FullTextQuery))
                    {
                        if (param.FullTextQuery.StartsWith("*"))
                        {
                            if (param.FullTextQuery != "*All*" && param.FullTextQuery != "*" && param.FullTextQuery != "**")
                            {
                                SearcherMethods.ApplyFullTextClause(booleanQuery, param.FullTextQuery, indexName);
                            }
                        }
                    }

                    SearcherMethods.ApplyAuthor(booleanQuery, param.Author);
                    SearcherMethods.ApplyDateRangeSearchParam(booleanQuery, param, innerOccurance);
                    if (param.Refinements.ContainsKey("__workflow state"))
                    {
                        SearcherMethods.AddFieldValueClause(booleanQuery, "__workflow state", param.Refinements["__workflow state"], QueryOccurance.Should);
                    }
                    if (Config.EnableBucketDebug || Constants.EnableTemporaryBucketDebug)
                    {
                        Log.Info("Search Clauses Number: " + booleanQuery.Clauses().Count, this);
                    }

                    if (!param.SortByField.IsNullOrEmpty())
                    {
                        return(this.RunQuery(booleanQuery, param.PageSize, param.PageNumber, param.SortByField, param.SortDirection));
                    }

                    return(param.PageNumber != 0 ? this.RunQuery(booleanQuery, param.PageSize, param.PageNumber) : this.RunQuery(booleanQuery, 20, 0));
                }
            }

            return(new KeyValuePair <int, List <SitecoreItem> >());
        }
        public virtual Dictionary <string, int> RunFacet(Query query, bool showAllVersions, bool isFacet, bool isIdLookup, int pageSize, int pageNumber, string termName, List <string> termValue, BitArray queryBase, string locationFilter)
        {
            var runningCOunt = new Dictionary <string, int>();
            var db           = Context.ContentDatabase ?? Sitecore.Context.Database;
            var indexName    = BucketManager.GetContextIndex(db.GetItem(locationFilter));

            if (indexName.EndsWith("_remote"))
            {
                Index = RemoteSearchManager.GetIndex(indexName) as RemoteIndex;
            }
            else if (indexName.EndsWith("_inmemory"))
            {
                Index = InMemorySearchManager.GetIndex(indexName) as InMemoryIndex;
            }
            else
            {
                Index = SearchManager.GetIndex(indexName) as Index;
            }
            using (var context = new SortableIndexSearchContext(Index))
            {
                if (Config.EnableBucketDebug || Constants.EnableTemporaryBucketDebug)
                {
                    Log.Info("Using: " + indexName, this);
                    Log.Info("Bucket Facet Original Debug Query: " + query, this);
                }

                foreach (var terms in termValue)
                {
                    var genreQueryFilter = GenreQueryFilter(query, isFacet, isIdLookup, termName, terms);
                    var tempSearchArray  = queryBase.Clone() as BitArray;
                    if (Config.EnableBucketDebug || Constants.EnableTemporaryBucketDebug)
                    {
                        Log.Info("Bucket Facet Debug Query: " + genreQueryFilter, this);
                    }

                    BitArray genreBitArray = genreQueryFilter.Bits(context.Searcher.GetIndexReader());
                    if (tempSearchArray.Length == genreBitArray.Length)
                    {
                        BitArray combinedResults = tempSearchArray.And(genreBitArray);

                        var cardinality = SearchHelper.GetCardinality(combinedResults);

                        if (cardinality > 0)
                        {
                            if (!isFacet)
                            {
                                if (!runningCOunt.ContainsKey(terms))
                                {
                                    runningCOunt.Add(terms, cardinality);
                                }
                            }
                            else
                            {
                                if (!runningCOunt.ContainsKey(terms))
                                {
                                    runningCOunt.Add(terms, cardinality);
                                }
                            }
                        }
                    }
                }
            }

            return(runningCOunt);
        }