Exemple #1
0
        public ProductSearchResultAdv DoProductSearchForAllStores(string query, ProductSearchQueryAdv queryAdv,
                                                                  int pageNumber, int pageSize)
        {
            var culture   = Context.MainContentCulture;
            var accountId = Context.CurrentAccount != null ? Context.CurrentAccount.Bvin : string.Empty;

            return(CacheManager.GetSearchResult(null, query, culture, queryAdv, pageNumber, pageSize, accountId,
                                                () => { return searcher.DoSearch(query, culture, queryAdv, pageNumber, pageSize); }));
        }
        // Search Results
        public static ProductSearchResultAdv GetSearchResult(long?storeId, string query, string culture,
                                                             ProductSearchQueryAdv queryAdv, int pageNumber, int pageSize, string accountId,
                                                             Func <ProductSearchResultAdv> getData)
        {
            var cachekeyTemplate = "storeid-{0}-searchresult-{1}-{2}-{3}-{4}-{5}-{6}";
            var queryHash        = MD5HashGenerator.GenerateKey(queryAdv);
            var cacheKey         = string.Format(cachekeyTemplate, storeId, query, culture, queryHash, pageNumber, pageSize,
                                                 accountId);

            return(GetItem(cacheKey, getData));
        }
Exemple #3
0
        public ProductSearchResultAdv DoProductSearch(long siteId, string query, ProductSearchQueryAdv queryAdv,
                                                      int pageNumber, int pageSize, bool logSearchQuery = false)
        {
            var culture   = Context.MainContentCulture;
            var accountId = Context.CurrentAccount != null ? Context.CurrentAccount.Bvin : string.Empty;

            if (logSearchQuery)
            {
                var searchQuery = new SearchQuery
                {
                    QueryPhrase = query,
                    ShopperID   = accountId
                };
                QueryRepository.Create(searchQuery);
            }

            return(CacheManager.GetSearchResult(siteId, query, culture, queryAdv, pageNumber, pageSize, accountId,
                                                () => { return searcher.DoSearch(siteId, query, culture, queryAdv, pageNumber, pageSize); }));
        }
        private ProductSearchQueryAdv BuildDrillDownQuery(CategoryFilterViewModel filter)
        {
            var queryAdv = new ProductSearchQueryAdv
            {
                MinPrice      = filter.MinPrice,
                MaxPrice      = filter.MaxPrice,
                Manufacturers = filter.Manufacturers ?? new List <string>(),
                Vendors       = filter.Vendors ?? new List <string>(),
                Types         = filter.Types ?? new List <string>(),
                Categories    = new List <string> {
                    filter.CategoryId
                },
                Properties = string.IsNullOrEmpty(filter.PropertiesJson)
                    ? new Dictionary <long, string[]>()
                    : JsonConvert.DeserializeObject <Dictionary <long, string[]> >(filter.PropertiesJson),
                IsConsiderSearchable = filter.IsConsiderSearchable,
                IsSearchable         = filter.IsSearchable
            };

            var cat = HccApp.CatalogServices.Categories.Find(filter.CategoryId);

            queryAdv.SortOrder = filter.SortOrder != CategorySortOrder.None ? filter.SortOrder : cat != null ? cat.DisplaySortOrder : CategorySortOrder.None;
            return(queryAdv);
        }
        public ActionResult Index(string search, int pageSize = 9)
        {
            // Initial Setup
            PageDescription += " | " + search;
            ViewBag.Search   = search;

            var model = new SearchPageViewModel();

            if (!string.IsNullOrEmpty(search))
            {
                // Pager Vars
                var pageNumber     = GetPageNumber();
                var logSearchQuery = pageNumber == 1;

                // Do Search
                var manager  = new SearchManager(HccApp.CurrentRequestContext);
                var queryAdv = new ProductSearchQueryAdv();
                if (!string.IsNullOrEmpty(Request.Params["categories"]))
                {
                    queryAdv.Categories = Request.Params["categories"].Split(',').ToList();
                    logSearchQuery      = false;
                }
                if (!string.IsNullOrEmpty(Request.Params["types"]))
                {
                    queryAdv.Types = Request.Params["types"].Split(',').ToList();
                    logSearchQuery = false;
                }
                if (!string.IsNullOrEmpty(Request.Params["manufacturers"]))
                {
                    queryAdv.Manufactures = Request.Params["manufacturers"].Split(',').ToList();
                    logSearchQuery        = false;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendors"]))
                {
                    queryAdv.Vendors = Request.Params["vendors"].Split(',').ToList();
                    logSearchQuery   = false;
                }

                var keys = Request.Params.AllKeys.
                           Where(k => k != null && k.StartsWith("prop")).
                           ToList();

                foreach (var key in keys)
                {
                    var propId    = int.Parse(key.Substring(4));
                    var propValue = Request.Params[key];
                    queryAdv.Properties.Add(propId, new[] { propValue });
                }
                if (keys.Count > 0)
                {
                    logSearchQuery = false;
                }

                if (!string.IsNullOrEmpty(Request.Params["minprice"]))
                {
                    queryAdv.MinPrice = decimal.Parse(Request.Params["minprice"], CultureInfo.InvariantCulture);
                    logSearchQuery    = false;
                }
                if (!string.IsNullOrEmpty(Request.Params["maxprice"]))
                {
                    queryAdv.MaxPrice = decimal.Parse(Request.Params["maxprice"], CultureInfo.InvariantCulture);
                    logSearchQuery    = false;
                }

                if (logSearchQuery && HttpContext.Items["HccSearchQueryLogged"] == null)
                {
                    HttpContext.Items["HccSearchQueryLogged"] = true;
                }
                else
                {
                    logSearchQuery = false;
                }

                var result = manager.DoProductSearch(HccApp.CurrentStore.Id,
                                                     search,
                                                     queryAdv,
                                                     pageNumber,
                                                     pageSize,
                                                     logSearchQuery);
                var products = HccApp.CatalogServices.Products.FindManyWithCache(result.Products);

                var searchSettings = new SearchModuleSettings(ModuleContext.ModuleId);

                model.ShowManufactures = searchSettings.ShowManufactures;
                model.ShowVendors      = searchSettings.ShowVendors;

                model.Categories   = result.Categories;
                model.Types        = result.Types;
                model.Manufactures = result.Manufacturers;
                model.Vendors      = result.Vendors;
                model.Properties   = result.Properties;
                model.MinPrice     = result.MinPrice;
                model.MaxPrice     = result.MaxPrice;

                model.SelectedCategories   = result.SelectedCategories;
                model.SelectedTypes        = result.SelectedTypes;
                model.SelectedManufactures = result.SelectedManufacturers;
                model.SelectedVendors      = result.SelectedVendors;
                model.SelectedProperties   = result.SelectedProperties;
                model.SelectedMinPrice     = result.SelectedMinPrice;
                model.SelectedMaxPrice     = result.SelectedMaxPrice;

                model.Products              = PrepProducts(products);
                model.PagerData.PageSize    = pageSize;
                model.PagerData.TotalItems  = result.TotalCount;
                model.PagerData.CurrentPage = pageNumber;
                model.PagerData.PageRange   = 20;

                var      currentParams = new List <string>();
                string[] parameters    =
                {
                    "search", "categories", "types", "manufacturers", "vendors", "minprice",
                    "maxprice"
                };
                var props = Request.QueryString.AllKeys.
                            Where(k => k != null && k.StartsWith("prop")).
                            ToList();
                currentParams.AddRange(parameters);
                currentParams.AddRange(props);
                foreach (var param in currentParams)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString[param]))
                    {
                        model.CurrentRouteValues[param] = HttpUtility.UrlEncode(Request.QueryString[param]);
                    }
                }

                var routeValues = new RouteValueDictionary(model.CurrentRouteValues);
                model.PagerData.PagerUrlFormatFirst = Url.RouteHccUrl(HccRoute.Search, routeValues);
                routeValues.Add("p", "{0}");
                model.PagerData.PagerUrlFormat = Url.RouteHccUrl(HccRoute.Search, routeValues);
            }

            return(View(model));
        }