Example #1
0
        public void ApplyCategorySorting()
        {
            switch (_searchQuery.SortBy)
            {
            case SearchQueryConstants.Price:
                // dont need any special sortings from the searchindex
                break;

            case SearchQueryConstants.Name:
                // dont need any special sortings from the searchindex
                break;

            case SearchQueryConstants.News:
                var tagName = "News".GetFieldDefinitionForProducts()?.GetTagName(CultureInfo.CurrentCulture);
                if (tagName != null)
                {
                    _request.Sortings.Add(new Sorting(tagName, SortDirection.Descending, SortingFieldType.Date));
                }
                break;

            case SearchQueryConstants.Popular:
                _request.Sortings.Add(new Sorting(FilteringConstants.GetMostSoldTagName(_requestModelAccessor.RequestModel.WebsiteModel.SystemId), SortDirection.Descending, SortingFieldType.Float));
                break;

            case SearchQueryConstants.Recommended:
                if (_searchQuery.CategorySystemId != null)
                {
                    _request.Sortings.Add(new Sorting(TagNames.GetTagNameForCategorySortIndex(_searchQuery.CategorySystemId.Value), SortDirection.Ascending, SortingFieldType.Int));
                }
                break;

            default:
            {
                if (!string.IsNullOrWhiteSpace(_searchQuery.Text) || _requestModelAccessor.RequestModel.CurrentPageModel.IsSearchResultPageType())
                {
                    // always sort products by their score, if no free-text is entered the score will be the same for all the products
                    _request.Sortings.Add(new Sorting(string.Empty, SortingFieldType.Score));
                }
                else
                {
                    if (_searchQuery.Type == SearchType.Products)
                    {
                        goto case SearchQueryConstants.Popular;
                    }
                    if (_searchQuery.Type == SearchType.Category)
                    {
                        goto case SearchQueryConstants.Recommended;
                    }
                }
                goto case SearchQueryConstants.Name;
            }
            }

            // default sorting is to always sort products after their name, article number
            _request.Sortings.Add(new Sorting(TagNames.Name, _searchQuery.SortDirection, SortingFieldType.String));
            _request.Sortings.Add(new Sorting(TagNames.ArticleNumber, SortingFieldType.String));
        }
        public IndexDocument PreProcessDocument(IndexDocument document, string indexName)
        {
            if (ProductCatalogSearchDomains.Products.Equals(indexName, StringComparison.OrdinalIgnoreCase))
            {
                var articleIds = document.Tags.Where(x => x.Name.Equals(TagNames.VariantSystemId, StringComparison.OrdinalIgnoreCase)).Select(x => (Guid)x.OriginalValue).ToList();
                foreach (var item in articleIds
                    .SelectMany(_campaignDataHolder.GetArticleCampaigns)
                    .GroupBy(x => x.CampaignId)
                    .Select(x => new { x.Key, Price = x.Min(z => z.Price) }))
                {
                    document.Tags.Add(new ReadableDocumentTag(FilteringConstants.GetCampaignTagName(item.Key), item.Price));
                }
            }

            return document;
        }
Example #3
0
        public IndexDocument PreProcessDocument(IndexDocument document, string indexName)
        {
            if (ProductCatalogSearchDomains.Products.Equals(indexName, StringComparison.OrdinalIgnoreCase))
            {
                var articleNumberTagName = TagNames.ArticleNumber;
                if (bool.TryParse(document.Tags.Where(x => TagNames.UseVariantUrl.Equals(x.Name, StringComparison.OrdinalIgnoreCase)).Select(x => x.Value).FirstOrDefault(), out bool useVariantUrl) && !useVariantUrl)
                {
                    articleNumberTagName = TagNames.VariantArticleNumbers;
                }

                IDictionary <Guid, decimal> allItems = new Dictionary <Guid, decimal>();
                var articleNumbers = document.Tags.Where(x => articleNumberTagName.Equals(x.Name, StringComparison.OrdinalIgnoreCase)).Select(x => x.Value);
                foreach (var articleNumber in articleNumbers)
                {
                    if (_mostSoldDataHolder.TryGet(articleNumber, out IDictionary <Guid, decimal> items))
                    {
                        foreach (var item in items)
                        {
                            if (allItems.TryGetValue(item.Key, out decimal currentItem))
                            {
                                allItems[item.Key] = currentItem + item.Value;
                            }
                            else
                            {
                                allItems[item.Key] = item.Value;
                            }
                        }
                    }
                }

                foreach (var item in allItems)
                {
                    document.Tags.Add(new DocumentTag(FilteringConstants.GetMostSoldTagName(item.Key), item.Value));
                }

                foreach (var item in _webSiteIds.Except(allItems.Keys))
                {
                    document.Tags.Add(new DocumentTag(FilteringConstants.GetMostSoldTagName(item), 0));
                }
            }

            return(document);
        }