private async Task BuildOtherSearchResultAsync(SearchResultViewModel searchResult, SearchQuery searchQuery)
        {
            var p = searchQuery.PageSize;

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

            var pageSearchResult = await _pageSearchService.SearchAsync(searchQuery, includeScore : true);

            var categorySearchResult = await _categorySearchService.SearchAsync(searchQuery, includeScore : true);

            searchQuery.PageSize           = p;
            searchResult.OtherSearchResult = new SearchResult
            {
                PageSize = 100,
                Total    = (pageSearchResult?.Total ?? 0) + (categorySearchResult?.Total ?? 0),
                Items    = new Lazy <IEnumerable <SearchResultItem> >(() => (
                                                                          pageSearchResult == null
                    ? Array.Empty <SearchResultItem>()
                    : pageSearchResult.Items.Value
                                                                          ).Concat(
                                                                          categorySearchResult == null
                        ? Array.Empty <SearchResultItem>()
                        : categorySearchResult.Items.Value).OrderByDescending(x => x.Score))
            };
        }
Ejemplo n.º 2
0
        private async Task <IEnumerable <SubNavigationLinkModel> > GetNewsChildLinksAsync(Page rootPage)
        {
            var searchQuery = _requestModelAccessor.RequestModel.SearchQuery.Clone();

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

            var searchResult = await _pageSearchService.SearchAsync(searchQuery);

            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.CurrentUICulture.Name,
                Url = _urlService.GetUrl(child),
                IsSelected = _currentSelectedPageId == child.SystemId
            })
                   .ToList());
        }
        public override async Task <SearchResult> SearchAsync(SearchQuery searchQuery, bool?onlyBrands = null, bool includeScore = false)
        {
            if (!_searchClientService.IsConfigured)
            {
                return(await _parent.SearchAsync(searchQuery, onlyBrands));
            }

            var response = await _searchClientService
                           .SearchAsync <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)
                                        ? SearchInBrands(q, onlyBrands) && q.PublishedOnWebsite() && SearchByText(q, searchQuery.Text, Fuzziness.Auto)
                                        : q.PublishedOnWebsite()))
                                                       .Sort(x => searchQuery.PageType == PageTemplateNameConstants.NewsList ? x.Descending(f => f.NewsDate) : null)
                                                       .Source(x => x.Includes(z => z.Fields(p => p.PageSystemId))));

            return(Transform(searchQuery, unchecked ((int)response.Total), () =>
            {
                var pages = _pageService.Get(response.Hits.Select(x => x.Source.PageSystemId));
                var pageLookup = includeScore ? response.Hits.ToDictionary(x => x.Source.PageSystemId, x => x.Score.GetValueOrDefault()) : null;

                return pages.Select(x => new PageSearchResult
                {
                    Item = x,
                    Id = x.SystemId,
                    Name = x.Localizations.CurrentUICulture.Name,
                    Url = _urlService.GetUrl(x),
                    Score = includeScore ? pageLookup.TryGetValue(x.SystemId, out var dbl) ? (float)dbl : default : default
                });
Ejemplo n.º 4
0
        public override async Task <SearchResult> QueryCompactAsync(string query, bool includeScore = false)
        {
            var searchQuery = _requestModelAccessor.RequestModel.SearchQuery.Clone();

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

            return(await _pageSearchService.SearchAsync(searchQuery, onlyBrands : OnlyBrands, includeScore : includeScore));
        }