Example #1
0
        public static string GetUrl(this SearchQuery searchQuery, Action <SearchQuery> action = null)
        {
            var query = action == null ? searchQuery : searchQuery.Clone();

            if (action != null)
            {
                query.PageNumber = 1;
                //if (CurrentState.Current.PageType.Name.IsBrandPageType())
                //{
                //    query.NamedData = null;
                //}
                action(query);
            }

            var sb = new StringBuilder();

            if (query.Type != default)
            {
                sb.Append("&");
                sb.Append(SearchQueryConstants.Type);
                sb.Append("=");
                sb.Append(query.Type);
            }

            if (query.Category != null)
            {
                foreach (var item in query.Category)
                {
                    sb.Append("&");
                    sb.Append(SearchQueryConstants.Category);
                    sb.Append("=");
                    sb.Append(HttpUtility.UrlEncode(item.ToString("N")));
                }
            }

            if (query.Tags != null)
            {
                foreach (var tag in query.Tags)
                {
                    if (tag.Value.Count > 0)
                    {
                        foreach (var value in tag.Value)
                        {
                            sb.Append("&");
                            sb.Append(HttpUtility.UrlEncode(tag.Key));
                            sb.Append("=");
                            sb.Append(HttpUtility.UrlEncode(value));
                        }
                    }
                }
            }

            if (query.PriceRanges != null)
            {
                foreach (var value in query.PriceRanges)
                {
                    sb.Append("&");
                    sb.Append(HttpUtility.UrlEncode(SearchQueryConstants.PriceRange));
                    sb.Append("=");
                    sb.Append(HttpUtility.UrlEncode(string.Format("{0}-{1}", value.Item1, value.Item2)));
                }
            }

            if (query.NewsDate != null)
            {
                sb.Append("&");
                sb.Append(HttpUtility.UrlEncode(SearchQueryConstants.News));
                sb.Append("=");
                sb.Append(HttpUtility.UrlEncode(string.Format("{0:yyyyMMdd}-{1:yyyyMMdd}", query.NewsDate.Item1, query.NewsDate.Item2)));
            }

            if (query.PageNumber > 1)
            {
                sb.Append("&");
                sb.Append(SearchQueryConstants.Page);
                sb.Append("=");
                sb.Append(query.PageNumber);
            }

            if (!string.IsNullOrEmpty(query.SortBy))
            {
                sb.Append("&");
                sb.Append(SearchQueryConstants.SortBy);
                sb.Append("=");
                sb.Append(query.SortBy);
            }
            if (query.SortDirection == Framework.Search.SortDirection.Descending)
            {
                sb.Append("&");
                sb.Append(SearchQueryConstants.SortDirection);
                sb.Append("=");
                sb.Append(Framework.Search.SortDirection.Descending.ToString());
            }

            if (!string.IsNullOrEmpty(query.Text))
            {
                sb.Append("&");
                sb.Append(HttpUtility.UrlEncode(SearchQueryConstants.Text));
                sb.Append("=");
                sb.Append(HttpUtility.UrlEncode(query.Text));
            }

            string url = searchQuery.BaseUrl;

            if (url == null)
            {
                if (query.PageType == PageTemplateNameConstants.SearchResult || query.PageType == PageTemplateNameConstants.Brand || query.PageType == PageTemplateNameConstants.ProductList)
                {
                    url = IoC.Resolve <UrlService>().GetUrl(query.PageSystemId.MapTo <Page>());
                }
                else
                {
                    url = (query.CategorySystemId.GetValueOrDefault() != Guid.Empty)
                        ? IoC.Resolve <UrlService>().GetUrl(query.CategorySystemId.Value.MapTo <Category>())
                        : query.WebsiteSystemId.MapTo <WebsiteModel>().Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.SearchResultPage)?.MapTo <LinkModel>()?.Href;
                }
                searchQuery.BaseUrl = url;
            }

            if (sb.Length > 1)
            {
                sb.Remove(0, 1);
                return(url + "?" + sb);
            }

            return(url);
        }
Example #2
0
 public static bool ContainsNewsFilter(this SearchQuery searchQuery)
 {
     return(searchQuery.NewsDate != null);
 }
Example #3
0
 public static bool ContainsPriceFilter(this SearchQuery searchQuery)
 {
     return(searchQuery.PriceRanges.Count > 0);
 }
Example #4
0
 public static bool ContainsCategoryFilter(this SearchQuery searchQuery)
 {
     return(searchQuery.Category.Count > 0);
 }
Example #5
0
 public static bool ContainsMultipleFilters(this SearchQuery searchQuery)
 {
     return(searchQuery.Tags.Count + searchQuery.Category.Count + (searchQuery.ContainsNewsFilter() ? 1 : 0) + searchQuery.PriceRanges.Count > 1);
 }
Example #6
0
 public static string GetUrlPrice(this SearchQuery searchQuery, (int, int) priceRange, bool selected)
Example #7
0
        protected GroupFilter GetFilterTag(SearchQuery searchQuery, FieldDefinition field, Dictionary <string, int> tagValues)
        {
            if (!searchQuery.Tags.TryGetValue(field.Id, out ISet <string> selectedValues))
            {
                selectedValues = new SortedSet <string>(StringComparer.OrdinalIgnoreCase);
            }

            return(new GroupFilter
            {
                Name = field.Localizations.CurrentCulture.Name ?? field.Id,
                Attributes = new Dictionary <string, string>
                {
                    { "value", NormalizeTag(field.Id) },
                },
                IsSelected = searchQuery.Tags.ContainsKey(field.Id),
                Links = tagValues
                        .Select(x =>
                {
                    string key;
                    switch (field.FieldType)
                    {
                    case SystemFieldTypeConstants.Decimal:
                    case SystemFieldTypeConstants.Int:
                        {
                            key = x.Key.TrimStart('0');
                            break;
                        }

                    case SystemFieldTypeConstants.Date:
                    case SystemFieldTypeConstants.DateTime:
                        {
                            if (long.TryParse(x.Key, NumberStyles.Any, CultureInfo.InvariantCulture, out long l))
                            {
                                key = new DateTime(l).ToShortDateString();
                            }
                            else
                            {
                                goto default;
                            }
                            break;
                        }

                    default:
                        {
                            key = x.Key;
                            break;
                        }
                    }

                    var selected = selectedValues.Contains(x.Key);

                    return new FilterItem
                    {
                        Name = key,
                        IsSelected = selected,
                        Url = searchQuery.GetUrlTag(field.Id, x.Key, selected),
                        Count = x.Value,
                        Attributes = new Dictionary <string, string>
                        {
                            { "value", NormalizeTag(x.Key) },
                            { "cssValue", (FindValue(field, key, CultureInfo.CurrentCulture) ?? key)?.ToLowerInvariant() },
                        }
                    };
                })
                        .OrderByDescending(x => x.Count)
                        .ThenBy(x => x.Name)
                        .ToList()
            });
Example #8
0
 public abstract IEnumerable <GroupFilter> GetFilter(SearchQuery searchQuery, IEnumerable <string> fieldNames);