/// <summary>
        /// Searches the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="skip">The skip.</param>
        /// <param name="take">The take.</param>
        /// <param name="hitCount">The hit count.</param>
        /// <returns></returns>
        public IEnumerable <IDocument> Search(string query, string language, int skip, int take, out int hitCount)
        {
            var service          = Telerik.Sitefinity.Services.ServiceBus.ResolveService <ISearchService>();
            var queryBuilder     = ObjectFactory.Resolve <IQueryBuilder>();
            var config           = Config.Get <SearchConfig>();
            var enableExactMatch = config.EnableExactMatch;

            var searchQuery = queryBuilder.BuildQuery(query, this.SearchFields);

            searchQuery.IndexName         = this.IndexCatalogue;
            searchQuery.Skip              = skip;
            searchQuery.Take              = take;
            searchQuery.OrderBy           = this.GetOrderList();
            searchQuery.EnableExactMatch  = enableExactMatch;
            searchQuery.HighlightedFields = this.HighlightedFields;

            ISearchFilter filter;

            if (this.TryBuildLanguageFilter(language, out filter))
            {
                searchQuery.Filter = filter;
            }

            var        oldSkipValue = skip;
            IResultSet result       = service.Search(searchQuery);

            hitCount = result.HitCount;

            return(result.SetContentLinks());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Searches the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="language">The language.</param>
        /// <param name="skip">The skip.</param>
        /// <param name="take">The take.</param>
        /// <param name="hitCount">The hit count.</param>
        /// <returns></returns>
        public IEnumerable <IDocument> Search(string query, string language, int skip, int take, out int hitCount)
        {
            var service          = Telerik.Sitefinity.Services.ServiceBus.ResolveService <ISearchService>();
            var queryBuilder     = ObjectFactory.Resolve <IQueryBuilder>();
            var config           = Config.Get <SearchConfig>();
            var enableExactMatch = config.EnableExactMatch;

            var searchQuery = queryBuilder.BuildQuery(query, this.SearchFields);

            searchQuery.IndexName         = this.IndexCatalogue;
            searchQuery.Skip              = skip;
            searchQuery.Take              = take;
            searchQuery.OrderBy           = this.GetOrderList();
            searchQuery.EnableExactMatch  = enableExactMatch;
            searchQuery.HighlightedFields = this.HighlightedFields;

            ISearchFilter filter;

            if (this.TryBuildLanguageFilter(language, out filter))
            {
                searchQuery.Filter = filter;
            }

            var oldSkipValue     = skip;
            var permissionFilter = config.EnableFilterByViewPermissions;

            if (permissionFilter)
            {
                Func <int, int, IEnumerable <Document> > searchResults = delegate(int querySkip, int queryTake)
                {
                    searchQuery.Skip = querySkip;
                    searchQuery.Take = queryTake;
                    var results = service.Search(searchQuery);

                    return(results.OfType <Document>());
                };

                var loader = new FilteredDataItemsLoader <Document>(searchResults);

                bool hasMoreItems = false;
                var  items        = loader.ValidateDataItems <Document>(PermissionsFilter.PermissionAction.View, out hasMoreItems, take, skip, (i, j) => i);

                oldSkipValue++;

                // Value will always show one more, when hasMoreItems is true. It also be at least one.
                if (hasMoreItems)
                {
                    hitCount = items.Count() + oldSkipValue;
                }
                else
                {
                    if (skip == 0 && take == int.MaxValue)
                    {
                        hitCount = items.Count();
                    }
                    else
                    {
                        hitCount = oldSkipValue;
                    }
                }

                return(items.Cast <IDocument>().SetContentLinks());
            }
            else
            {
                IResultSet result = service.Search(searchQuery);
                hitCount = result.HitCount;

                return(result.SetContentLinks());
            }
        }