コード例 #1
0
        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);
        }
コード例 #2
0
        private List <List <FacetReturn> > GetFacets()
        {
            var ret    = new List <List <FacetReturn> >();
            var facets = Context.ContentDatabase.GetItem(Constants.FacetFolder).Children;

            foreach (Item facet in facets)
            {
                if (facet.Fields["Enabled"].Value == "1")
                {
                    // pull the type off of the Sitecore item
                    string typeName = facet.Fields["Type"].Value;
                    object type     = Sitecore.Reflection.ReflectionUtil.CreateObject(typeName);

                    // pull any parameters out of the Sitecore item
                    string typeParameters = facet.Fields["Parameters"].Value;
                    if (!string.IsNullOrEmpty(typeParameters))
                    {
                        Sitecore.Reflection.ReflectionUtil.SetProperties(type, typeParameters);
                    }

                    if ((type as IFacet).IsNotNull())
                    {
                        var locationOverride = GetLocationOverride();
                        using (var context = new SortableIndexSearchContext(SearchManager.GetIndex(BucketManager.GetContextIndex(Context.ContentDatabase.GetItem(locationOverride)))))
                        {
                            var query          = SearchHelper.GetBaseQuery(this._searchQuery, locationOverride);
                            var queryBase      = IndexSearcher.ContructQuery(query);
                            var searchBitArray = new QueryFilter(queryBase).Bits(context.Searcher.GetIndexReader());
                            var res            = ((IFacet)type).Filter(queryBase, this._searchQuery, locationOverride, searchBitArray);
                            ret.Add(res);
                        }
                    }
                }
            }

            return(ret);
        }
コード例 #3
0
        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> >());
        }
コード例 #4
0
 public IndexSearcher(string indexId)
 {
     Index = SearchManager.GetIndex(BucketManager.GetContextIndex(Sitecore.Context.Item));
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IndexSearcher"/> class.
 /// </summary>
 /// <param name="indexId">The index id.</param>
 public IndexSearcher(string indexId)
 {
     this.searcherIndexName = indexId;
     Index = SearchManager.GetIndex(BucketManager.GetContextIndex(Context.Item));
 }
コード例 #7
0
        private List <List <FacetReturn> > GetFacets()
        {
            var ret    = new List <List <FacetReturn> >();
            var facets = Context.ContentDatabase.GetItem(Constants.FacetFolder).Children;

            foreach (Item facet in facets)
            {
                if (facet.Fields["Enabled"].Value == "1")
                {
                    dynamic type = Activator.CreateInstance(Type.GetType(facet.Fields["Type"].Value));
                    if ((type as IFacet).IsNotNull())
                    {
                        var locationOverride = GetLocationOverride();
                        using (var context = new SortableIndexSearchContext(SearchManager.GetIndex(BucketManager.GetContextIndex(Context.ContentDatabase.GetItem(locationOverride)))))
                        {
                            var query          = SearchHelper.GetBaseQuery(this._searchQuery, locationOverride);
                            var queryBase      = IndexSearcher.ContructQuery(query);
                            var searchBitArray = new QueryFilter(queryBase).Bits(context.Searcher.GetIndexReader());
                            var res            = ((IFacet)type).Filter(queryBase, this._searchQuery, locationOverride, searchBitArray);
                            ret.Add(res);
                        }
                    }
                }
            }

            return(ret);
        }