コード例 #1
0
        private IEnumerable <SubNavigationLinkModel> GetNewsChildLinks(Page rootPage)
        {
            var searchQuery = _requestModelAccessor.RequestModel.SearchQuery.Clone();

            searchQuery.PageSize     = 5;
            searchQuery.PageNumber   = 1;
            searchQuery.PageType     = PageTemplateNameConstants.NewsList;
            searchQuery.PageSystemId = rootPage.SystemId;

            var searchResponse = _pageSearchService.Search(searchQuery);
            var searchResult   = _pageSearchService.Transform(searchQuery, searchResponse);

            if (searchResult == null || searchResult.Total < 1)
            {
                return(new List <SubNavigationLinkModel>());
            }

            return(_pageService.Get(searchResult.Items.Value.Select(x => x.Id).ToList())
                   .Where(p => p.IsActive(_channel.SystemId))
                   .Select(child =>
                           new SubNavigationLinkModel
            {
                Name = child.Localizations.CurrentCulture.Name,
                Url = _urlService.GetUrl(child),
                IsSelected = _currentSelectedPageId == child.SystemId
            })
                   .ToList());
        }
コード例 #2
0
        public override SearchResponse Search(SearchQuery searchQuery, bool?onlyBrands = null)
        {
            if (!_searchClientService.IsConfigured)
            {
                return(_parent.Search(searchQuery, onlyBrands));
            }

            var fuzziness = !string.IsNullOrEmpty(searchQuery.Text) ? (searchQuery.Text.Length > 2 ? Fuzziness.EditDistance(2) : Fuzziness.Auto) : null;

            return(new ElasticSearchResponse <PageDocument>(_searchClientService
                                                            .Search <PageDocument>(CultureInfo.CurrentUICulture, selector => selector
                                                                                   .From((searchQuery.PageNumber - 1) * searchQuery.PageSize.GetValueOrDefault(10000))
                                                                                   .Size(searchQuery.PageSize)
                                                                                   .QueryWithPermission(q =>
                                                                                                        q.PublishedOnChannel() &&
                                                                                                        (!string.IsNullOrEmpty(searchQuery.PageType)
                                ? SearchByPageType(q, searchQuery) && q.PublishedOnWebsite()
                                : !string.IsNullOrEmpty(searchQuery.Text)
                                        ? (onlyBrands == true ? SearchInBrands(q) && q.PublishedOnWebsite() : q.PublishedOnWebsite()) &&
                                                                                                         SearchByText(q, searchQuery.Text, fuzziness)
                                        : q.PublishedOnWebsite()))
                                                                                   .Sort(x => searchQuery.PageType == PageTemplateNameConstants.NewsList ? x.Descending(f => f.NewsDate) : null)
                                                                                   .Source(x => x.Includes(z => z.Fields(p => p.PageSystemId))))
                                                            ));
        }
コード例 #3
0
ファイル: PageSearcher.cs プロジェクト: Salle79/Accelerator
        public override SearchResult QueryCompact(string query, bool includeScore = false)
        {
            var searchQuery = _requestModelAccessor.RequestModel.SearchQuery.Clone();

            searchQuery.Text       = query;
            searchQuery.PageNumber = 1;
            searchQuery.PageSize   = PageSize;

            var searchResponse = _pageSearchService.Search(searchQuery, onlyBrands: OnlyBrands);

            if (searchResponse == null)
            {
                return(null);
            }

            return(_pageSearchService.Transform(searchQuery, searchResponse, includeScore: includeScore));
        }
コード例 #4
0
        private void BuildOtherSearchResult(SearchResultViewModel searchResult, SearchQuery searchQuery)
        {
            var p = searchQuery.PageSize;

            searchQuery.PageNumber = 1;
            searchQuery.PageSize   = 100;

            var searchResponse   = _pageSearchService.Search(searchQuery);
            var pageSearchResult = searchResponse != null?_pageSearchService.Transform(searchQuery, searchResponse, true) : null;

            searchResponse = _categorySearchService.Search(searchQuery);
            var categorySearchResult = searchResponse != null?_categorySearchService.Transform(searchQuery, searchResponse, true) : null;

            searchQuery.PageSize           = p;
            searchResult.OtherSearchResult = new SearchResult
            {
                PageSize = 100,
                Total    = (pageSearchResult?.Total ?? 0) + (categorySearchResult?.Total ?? 0),
                Items    = new Lazy <IEnumerable <SearchResultItem> >(() => (pageSearchResult == null ? new SearchResultItem[0] : pageSearchResult.Items.Value).Concat(categorySearchResult == null ? new SearchResultItem[0] : categorySearchResult.Items.Value).OrderByDescending(x => x.Score))
            };
        }