public CatalogItemSearchResults SearchItems(string scope, CatalogItemSearchCriteria criteria) { var results = _searchService.Search(scope, criteria) as SearchResults; var items = results.GetKeyAndOutlineFieldValueMap<string>(); var r = new CatalogItemSearchResults(criteria, items, results); return r; }
public void Can_find_item_lucene() { var scope = "default"; var queryBuilder = new LuceneSearchQueryBuilder(); var conn = new SearchConnection(_LuceneStorageDir, scope); var provider = new LuceneSearchProvider(queryBuilder, conn); if (Directory.Exists(_LuceneStorageDir)) { Directory.Delete(_LuceneStorageDir, true); } SearchHelper.CreateSampleIndex(provider, scope); var criteria = new CatalogItemSearchCriteria { SearchPhrase = "product", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Pricelists = new string[] { } }; var results = provider.Search(scope, criteria); Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount)); criteria = new CatalogItemSearchCriteria { SearchPhrase = "sample product ", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Pricelists = new string[] { } }; results = provider.Search(scope, criteria); Assert.True(results.DocCount == 1, String.Format("\"Sample Product\" search returns {0} instead of 1", results.DocCount)); Directory.Delete(_LuceneStorageDir, true); }
public ActionResult Index(SearchParameters parameters) { Logger.Info("New search started: " + parameters.FreeSearch); ViewBag.Title = String.Format("Searching by '{0}'", parameters.FreeSearch); var criteria = new CatalogItemSearchCriteria { SearchPhrase = parameters.FreeSearch, IsFuzzySearch = true, Catalog = UserHelper.CustomerSession.CatalogId }; RestoreSearchPreferences(parameters); var results = SearchResults(criteria, parameters); return View(results); }
public void Can_find_items_azuresearch() { var scope = "default"; var queryBuilder = new AzureSearchQueryBuilder(); var conn = new SearchConnection(Datasource, scope, accessKey: AccessKey); var provider = new AzureSearchProvider(queryBuilder, conn); var criteria = new CatalogItemSearchCriteria { SearchPhrase = "sony", IsFuzzySearch = true, Catalog = "vendorvirtual", RecordsToRetrieve = 10, StartingRecord = 0, Pricelists = new string[] { }, StartDate = DateTime.UtcNow, Sort = new SearchSort("price_usd_saleusd") }; criteria.Outlines.Add("vendorvirtual*"); //"(startdate lt 2014-09-26T22:05:11Z) and sys__hidden eq 'false' and sys__outline/any(t:t eq 'VendorVirtual/e1b56012-d877-4bdd-92d8-3fc186899d0f*') and catalog/any(t: t eq 'VendorVirtual')" var results = provider.Search(scope, criteria); }
public void Can_get_item_multiple_filters_lucene() { var scope = "default"; var queryBuilder = new LuceneSearchQueryBuilder(); var conn = new SearchConnection(_LuceneStorageDir, scope); var provider = new LuceneSearchProvider(queryBuilder, conn); Debug.WriteLine("Lucene connection: {0}", conn.ToString()); if (Directory.Exists(_LuceneStorageDir)) { Directory.Delete(_LuceneStorageDir, true); } SearchHelper.CreateSampleIndex(provider, scope); var criteria = new CatalogItemSearchCriteria { SearchPhrase = "", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Currency = "USD", Pricelists = new[] { "default" } }; var colorFilter = new AttributeFilter { Key = "Color" }; colorFilter.Values = new[] { new AttributeFilterValue { Id = "red", Value = "red" }, new AttributeFilterValue { Id = "blue", Value = "blue" }, new AttributeFilterValue { Id = "black", Value = "black" } }; var filter = new AttributeFilter { Key = "Color" }; filter.Values = new[] { new AttributeFilterValue { Id = "black", Value = "black" } }; var rangefilter = new RangeFilter { Key = "size" }; rangefilter.Values = new[] { new RangeFilterValue { Id = "0_to_5", Lower = "0", Upper = "5" }, new RangeFilterValue { Id = "5_to_10", Lower = "5", Upper = "11" } }; var priceRangefilter = new PriceRangeFilter { Currency = "usd" }; priceRangefilter.Values = new[] { new RangeFilterValue { Id = "100_to_700", Lower = "100", Upper = "700" } }; criteria.Add(colorFilter); criteria.Add(priceRangefilter); // add applied filters criteria.Apply(filter); //criteria.Apply(rangefilter); //criteria.Apply(priceRangefilter); var results = provider.Search(scope, criteria); var blackCount = GetFacetCount(results, "Color", "black"); Assert.True(blackCount == 1, String.Format("Returns {0} facets of black instead of 2", blackCount)); //Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount)); Directory.Delete(_LuceneStorageDir, true); }
/// <summary> /// Searches the items. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <returns></returns> public CatalogItemSearchResults SearchItems(CatalogItemSearchCriteria criteria, bool useCache = true) { var scope = _searchConnection.Scope; return Helper.Get( CacheHelper.CreateCacheKey(Constants.CatalogCachePrefix, string.Format(SearchCacheKey, scope, criteria.CacheKey)), () => _catalogService.SearchItems(scope, criteria), SearchConfiguration.Instance.Cache.FiltersTimeout, _isEnabled && useCache); }
/// <summary> /// Creates the data model. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="parameters">The parameters.</param> /// <param name="cacheResults">if set to <c>true</c> [cache results].</param> /// <returns>CatalogItemSearchModel.</returns> private CatalogItemSearchModel CreateDataModel(CatalogItemSearchCriteria criteria, SearchParameters parameters, bool cacheResults) { var session = UserHelper.CustomerSession; // Create a model var dataSource = new CatalogItemSearchModel(); // Now fill in filters var filters = _searchFilter.Filters; // Add all filters foreach (var filter in filters) { criteria.Add(filter); } // Get selected filters var facets = parameters.Facets; dataSource.SelectedFilters = new List<SelectedFilterModel>(); if (facets.Count != 0) { foreach (var key in facets.Keys) { var filter = filters.SingleOrDefault(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase) && (!(x is PriceRangeFilter) || ((PriceRangeFilter)x).Currency.Equals(StoreHelper.CustomerSession.Currency, StringComparison.OrdinalIgnoreCase))); var appliedFilter = _searchFilter.Convert(filter, facets[key]); foreach (var val in appliedFilter.GetValues()) { criteria.Apply(appliedFilter); dataSource.SelectedFilters.Add( new SelectedFilterModel(_searchFilter.Convert(filter), _searchFilter.Convert(val))); } } } // Perform search var sort = string.IsNullOrEmpty(parameters.Sort) ? "position" : parameters.Sort; var sortOrder = parameters.SortOrder; var isDescending = "desc".Equals(sortOrder, StringComparison.OrdinalIgnoreCase); SearchSort sortObject = null; switch (sort.ToLowerInvariant()) { case "price": if (session.Pricelists != null) { sortObject = new SearchSort(session.Pricelists.Select(priceList => new SearchSortField( String.Format("price_{0}_{1}", criteria.Currency.ToLower(), priceList.ToLower())) { IgnoredUnmapped = true, IsDescending = isDescending, DataType = SearchSortField.DOUBLE }) .ToArray()); } break; case "position": sortObject = new SearchSort(new SearchSortField(string.Format("sort{0}{1}",session.CatalogId,session.CategoryId).ToLower()) { IgnoredUnmapped = true, IsDescending = isDescending }); break; case "name": sortObject = new SearchSort("name", isDescending); break; case "rating": sortObject = new SearchSort(criteria.ReviewsAverageField, isDescending); break; case "reviews": sortObject = new SearchSort(criteria.ReviewsTotalField, isDescending); break; default: sortObject = CatalogItemSearchCriteria.DefaultSortOrder; break; } criteria.Sort = sortObject; CatalogItemSearchResults results; // Search using criteria, it will only return IDs of the items var items = Search(criteria, cacheResults, out results).ToArray(); var itemsIdsArray = items.Select(i => i.ItemId).ToArray(); // Now load items with appropriate var itemModelList = new List<CatalogItemWithPriceModel>(); if (items.Any()) { // Now convert it to the model var prices = _priceListClient.GetLowestPrices(session.Pricelists, itemsIdsArray, 1); var availabilities = _catalogClient.GetItemAvailability(itemsIdsArray, UserHelper.StoreClient.GetCurrentStore().FulfillmentCenterId); foreach (var item in items) { PriceModel priceModel = null; ItemAvailabilityModel availabilityModel = null; var searchTags = results.Items[item.ItemId.ToLower()]; var currentOutline = this.GetItemOutlineUsingContext(searchTags[criteria.OutlineField].ToString()); //Cache outline HttpContext.Items["browsingoutline_" + item.ItemId.ToLower()] = StripCatalogFromOutline(currentOutline); if (prices != null && prices.Any()) { var lowestPrice = (prices.Where(p => p.ItemId.Equals(item.ItemId, StringComparison.OrdinalIgnoreCase))).SingleOrDefault(); if (lowestPrice != null) { var tags = new Hashtable { { "Outline", currentOutline } }; priceModel = _marketing.GetItemPriceModel(item, lowestPrice, tags); } } if (availabilities != null && availabilities.Any()) { var availability = (from a in availabilities where a.ItemId.Equals(item.ItemId, StringComparison.OrdinalIgnoreCase) select a).SingleOrDefault(); availabilityModel = new ItemAvailabilityModel(availability); } var itemModel = new CatalogItemWithPriceModel(CatalogHelper.CreateItemModel(item), priceModel, availabilityModel) { SearchOutline = currentOutline }; try { itemModel.ItemReviewTotals.AverageRating = double.Parse(searchTags[criteria.ReviewsAverageField].ToString()); itemModel.ItemReviewTotals.TotalReviews = int.Parse(searchTags[criteria.ReviewsTotalField].ToString()); } catch { //There are no reviews indexed? } itemModelList.Add(itemModel); } } dataSource.FilterGroups = _searchFilter.Convert(results.FacetGroups); dataSource.CatalogItems = itemModelList.ToArray(); dataSource.Criteria = criteria; // Create pager var pager = new PagerModel { TotalCount = results.TotalCount, CurrentPage = criteria.StartingRecord / criteria.RecordsToRetrieve + 1, RecordsPerPage = criteria.RecordsToRetrieve, StartingRecord = criteria.StartingRecord, DisplayStartingRecord = criteria.StartingRecord + 1, SortValues = new[] { "Position", "Name", "Price", "Rating", "Reviews" }, SelectedSort = sort, SortOrder = isDescending ? "desc" : "asc" }; var end = criteria.StartingRecord + criteria.RecordsToRetrieve; pager.DisplayEndingRecord = end > results.TotalCount ? results.TotalCount : end; dataSource.Pager = pager; return dataSource; }
/// <summary> /// Gets the model from criteria. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="parameters">The parameters.</param> /// <returns>CatalogItemSearchModel.</returns> private CatalogItemSearchModel GetModelFromCriteria(CatalogItemSearchCriteria criteria, SearchParameters parameters) { criteria.Currency = UserHelper.CustomerSession.Currency; var dataSource = CreateDataModel(criteria, parameters, true); return dataSource; }
private List<Item> Search(CatalogItemSearchCriteria criteria, bool cacheResults, out CatalogItemSearchResults results) { var items = new List<Item>(); var itemsOrderedList = new List<string>(); int foundItemCount; int dbItemCount = 0; int searchRetry = 0; var myCriteria = criteria.Clone(); do { // Search using criteria, it will only return IDs of the items results = _catalogClient.SearchItems(myCriteria, cacheResults); searchRetry++; //Get only new found itemIds var uniqueKeys = results.Items.Keys.Except(itemsOrderedList).ToArray(); foundItemCount = uniqueKeys.Length; if (!results.Items.Any()) continue; itemsOrderedList.AddRange(uniqueKeys); // Now load items from repository var currentItems = _catalogClient.GetItems(uniqueKeys.ToArray(), cacheResults, ItemResponseGroups.ItemAssets | ItemResponseGroups.ItemProperties | ItemResponseGroups.ItemEditorialReviews); items.AddRange(currentItems.OrderBy(i => itemsOrderedList.IndexOf(i.ItemId))); dbItemCount = currentItems.Length; //If some items where removed and search is out of sync try getting extra items if (foundItemCount > dbItemCount) { //Retrieve more items to fill missing gap myCriteria.RecordsToRetrieve += (foundItemCount - dbItemCount); } } while (foundItemCount > dbItemCount && results.Items.Any() && searchRetry <= 3 && (myCriteria.RecordsToRetrieve + myCriteria.StartingRecord) < results.TotalCount); return items; }
public ActionResult Find(string term) { Logger.Info("New search started: " + term); ViewBag.Title = String.Format("Searching by '{0}'".Localize(), term); var parameters = new SearchParameters { PageSize = 15 }; var criteria = new CatalogItemSearchCriteria { SearchPhrase = term.EscapeSearchTerm(), IsFuzzySearch = true }; var results = SearchResults(criteria, parameters); var data = from i in results.CatalogItems select new { url = Url.ItemUrl(i.CatalogItem.Item, i.CatalogItem.ParentItemId), value = i.DisplayName }; return Json(data.ToArray(), JsonRequestBehavior.AllowGet); }
public ActionResult SearchResultsWithinCategory(CategoryModel cat, SearchParameters parameters, string name = "Index", CatalogItemSearchCriteria criteria = null, bool savePreferences = true) { criteria = criteria ?? new CatalogItemSearchCriteria(); if (cat != null) { ViewBag.Title = cat.DisplayName; criteria.Outlines.Add(String.Format("{0}*", _catalogClient.BuildCategoryOutline(UserHelper.CustomerSession.CatalogId, cat.Category))); } if (savePreferences) { RestoreSearchPreferences(parameters); } var results = SearchResults(criteria, parameters); return PartialView(name, results); }
protected void AddQueryString(string fieldName, BoolQuery<ESDocument> query, CatalogItemSearchCriteria filter) { var searchPhrase = filter.SearchPhrase; if (filter.IsFuzzySearch) { query.Must( q => q.Match( x => x.Field(fieldName).Operator(Operator.AND).Fuzziness(filter.FuzzyMinSimilarity).Query(searchPhrase))); } else { query.Must( q => q.Match( x => x.Field(fieldName).Operator(Operator.AND).Query(searchPhrase))); } }
/// <summary> /// Creates the data model. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="parameters">The parameters.</param> /// <param name="cacheResults">if set to <c>true</c> [cache results].</param> /// <returns>CatalogItemSearchModel.</returns> private CatalogItemSearchModel CreateDataModel(CatalogItemSearchCriteria criteria, SearchParameters parameters, bool cacheResults) { var session = UserHelper.CustomerSession; // Create a model var dataSource = new CatalogItemSearchModel(); // Now fill in filters var searchHelper = new SearchHelper(_storeClient.GetCurrentStore()); var filters = searchHelper.Filters; // Add all filters foreach (var filter in filters) { // Check if we already filtering if (parameters.Facets.Keys.Any(k => filter.Key.Equals(k, StringComparison.OrdinalIgnoreCase))) continue; criteria.Add(filter); } // Get selected filters var facets = parameters.Facets; dataSource.SelectedFilters = new List<SelectedFilterModel>(); if (facets.Count != 0) { foreach (var key in facets.Keys) { var filter = filters.SingleOrDefault(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase) && (!(x is PriceRangeFilter) || ((PriceRangeFilter)x).Currency.Equals(StoreHelper.CustomerSession.Currency, StringComparison.OrdinalIgnoreCase))); var val = (from v in searchHelper.GetFilterValues(filter) where v.Id == facets[key] select v) .SingleOrDefault(); if (val != null) { criteria.Add(filter, val); dataSource.SelectedFilters.Add(new SelectedFilterModel(searchHelper.Convert(filter), searchHelper.Convert(val))); } } } // Perform search var sort = string.IsNullOrEmpty(parameters.Sort) ? "position" : parameters.Sort; var sortOrder = parameters.SortOrder; bool isDescending = "desc".Equals(sortOrder, StringComparison.OrdinalIgnoreCase); SearchSort sortObject = null; if (!sort.Equals("position", StringComparison.OrdinalIgnoreCase)) { if (sort.Equals("price", StringComparison.OrdinalIgnoreCase)) { if (session.Pricelists != null) { sortObject = new SearchSort(session.Pricelists.Select(priceList => new SearchSortField( String.Format("price_{0}_{1}", criteria.Currency.ToLower(), priceList.ToLower())) { IgnoredUnmapped = true, IsDescending = isDescending, DataType = SearchSortField.DOUBLE }) .ToArray()); } } else { sortObject = new SearchSort(sort.ToLower(), isDescending); } } // Put default sort order if none is set if (sortObject == null) { sortObject = CatalogItemSearchCriteria.DefaultSortOrder; } criteria.Sort = sortObject; CatalogItemSearchResults results; // Search using criteria, it will only return IDs of the items var items = Search(criteria, cacheResults, out results).ToArray(); var itemsIdsArray = items.Select(i => i.ItemId).ToArray(); // Now load items with appropriate var itemModelList = new List<CatalogItemWithPriceModel>(); if (items.Any()) { // Now convert it to the model var prices = _priceListClient.GetLowestPrices(session.Pricelists, itemsIdsArray, 1); var availabilities = _catalogClient.GetItemAvailability(itemsIdsArray, UserHelper.StoreClient.GetCurrentStore().FulfillmentCenterId); foreach (var item in items) { PriceModel priceModel = null; ItemAvailabilityModel availabilityModel = null; var catalogIdPath = UserHelper.CustomerSession.CatalogId + "/"; var searchTags = results.Items[item.ItemId.ToLower()].ToPropertyDictionary(); //Cache outline HttpContext.Items["browsingoutline_" + item.Code.ToLower()] = searchTags[criteria.BrowsingOutlineField].ToString(); var currentOutline = searchTags[criteria.OutlineField].ToString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .FirstOrDefault(x => x.StartsWith(catalogIdPath, StringComparison.OrdinalIgnoreCase)) ?? string.Empty; if (prices != null && prices.Any()) { var lowestPrice = (from p in prices where p.ItemId.Equals(item.ItemId, StringComparison.OrdinalIgnoreCase) select p).SingleOrDefault(); if (lowestPrice != null) { var tags = new Hashtable { { "Outline", currentOutline } }; priceModel = _marketing.GetItemPriceModel(item, lowestPrice, tags); } } if (availabilities != null && availabilities.Any()) { var availability = (from a in availabilities where a.ItemId.Equals(item.ItemId, StringComparison.OrdinalIgnoreCase) select a).SingleOrDefault(); availabilityModel = new ItemAvailabilityModel(availability); } var itemModel = new CatalogItemWithPriceModel(CatalogHelper.CreateItemModel(item), priceModel, availabilityModel) { SearchOutline = currentOutline }; itemModelList.Add(itemModel); } } dataSource.FilterGroups = searchHelper.Convert(results.FacetGroups); dataSource.CatalogItems = itemModelList.ToArray(); dataSource.Criteria = criteria; // Create pager var pager = new PagerModel { TotalCount = results.TotalCount, CurrentPage = criteria.StartingRecord / criteria.RecordsToRetrieve + 1, RecordsPerPage = criteria.RecordsToRetrieve, StartingRecord = criteria.StartingRecord, DisplayStartingRecord = criteria.StartingRecord + 1, SortValues = new[] { "Position", "Name", "Price" }, SelectedSort = sort, SortOrder = isDescending ? "desc" : "asc" }; var end = criteria.StartingRecord + criteria.RecordsToRetrieve; pager.DisplayEndingRecord = end > results.TotalCount ? results.TotalCount : end; dataSource.Pager = pager; // Query similar words /* if (count == 0) dataSource.Suggestions = GetSuggestions(); * */ //} return dataSource; }
protected void AddQueryString(string fieldName, BoolQuery<ESDocument> query, CatalogItemSearchCriteria filter) { var searchPhrase = filter.SearchPhrase; if (filter.IsFuzzySearch) { var keywords = Regex.Split(searchPhrase, @"\s+"); searchPhrase = string.Empty; searchPhrase = keywords.Aggregate(searchPhrase, (current, keyword) => current + String.Format("{0}~{1}", keyword, filter.FuzzyMinSimilarity)); } query.Must(q => q.QueryString(t => t.DefaultField(fieldName).DefaultOperator(Operator.AND).Query(searchPhrase))); }
public void Can_find_item_azuresearch() { var scope = "test"; var queryBuilder = new AzureSearchQueryBuilder(); var conn = new SearchConnection(Datasource, scope, accessKey: AccessKey); var provider = new AzureSearchProvider(queryBuilder, conn); provider.RemoveAll(scope, String.Empty); SearchHelper.CreateSampleIndex(provider, scope); var criteria = new CatalogItemSearchCriteria { SearchPhrase = "product", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Pricelists = new string[] { } }; // force delay, otherwise records are not available Thread.Sleep(1000); var results = provider.Search(scope, criteria); Assert.True(results.DocCount == 1, String.Format("Returns {0} instead of 1", results.DocCount)); criteria = new CatalogItemSearchCriteria { SearchPhrase = "sample product ", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Pricelists = new string[] { } }; results = provider.Search(scope, criteria); Assert.True(results.DocCount == 1, String.Format("\"Sample Product\" search returns {0} instead of 1", results.DocCount)); provider.RemoveAll(scope, String.Empty); }
public void Can_get_item_facets_lucene() { var scope = "default"; var queryBuilder = new LuceneSearchQueryBuilder(); var conn = new SearchConnection(_LuceneStorageDir, scope); var provider = new LuceneSearchProvider(queryBuilder, conn); Debug.WriteLine("Lucene connection: {0}", conn.ToString()); if (Directory.Exists(_LuceneStorageDir)) { Directory.Delete(_LuceneStorageDir, true); } SearchHelper.CreateSampleIndex(provider, scope); var criteria = new CatalogItemSearchCriteria { SearchPhrase = "", IsFuzzySearch = true, Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, Currency = "USD", Pricelists = new[] { "default" } }; var filter = new AttributeFilter { Key = "Color" }; filter.Values = new[] { new AttributeFilterValue { Id = "red", Value = "red" }, new AttributeFilterValue { Id = "blue", Value = "blue" }, new AttributeFilterValue { Id = "black", Value = "black" } }; var rangefilter = new RangeFilter { Key = "size" }; rangefilter.Values = new[] { new RangeFilterValue { Id = "0_to_5", Lower = "0", Upper = "5" }, new RangeFilterValue { Id = "5_to_10", Lower = "5", Upper = "10" } }; var priceRangefilter = new PriceRangeFilter { Currency = "usd" }; priceRangefilter.Values = new[] { new RangeFilterValue { Id = "0_to_100", Lower = "0", Upper = "100" }, new RangeFilterValue { Id = "100_to_700", Lower = "100", Upper = "700" } }; criteria.Add(filter); criteria.Add(rangefilter); criteria.Add(priceRangefilter); var results = provider.Search(scope, criteria); Assert.True(results.DocCount == 4, String.Format("Returns {0} instead of 4", results.DocCount)); var redCount = GetFacetCount(results, "Color", "red"); Assert.True(redCount == 2, String.Format("Returns {0} facets of red instead of 2", redCount)); var priceCount = GetFacetCount(results, "Price", "0_to_100"); Assert.True(priceCount == 2, String.Format("Returns {0} facets of 0_to_100 prices instead of 2", priceCount)); var priceCount2 = GetFacetCount(results, "Price", "100_to_700"); Assert.True(priceCount2 == 2, String.Format("Returns {0} facets of 100_to_700 prices instead of 2", priceCount2)); var sizeCount = GetFacetCount(results, "size", "0_to_5"); Assert.True(sizeCount == 2, String.Format("Returns {0} facets of 0_to_5 size instead of 2", sizeCount)); var sizeCount2 = GetFacetCount(results, "size", "5_to_10"); Assert.True(sizeCount2 == 1, String.Format("Returns {0} facets of 5_to_10 size instead of 1", sizeCount2)); // only 1 result because upper bound is not included var outlineCount = results.Documents[0].Documents[0]["__outline"].Values.Count(); Assert.True(outlineCount == 2, String.Format("Returns {0} outlines instead of 2", outlineCount)); Directory.Delete(_LuceneStorageDir, true); }
public VirtoCommerce.Foundation.Catalogs.Search.CatalogItemSearchResults SearchItems(string scope, VirtoCommerce.Foundation.Catalogs.Search.CatalogItemSearchCriteria criteria) { var resultDocumentSet = new ResultDocumentSet(); resultDocumentSet.TotalCount = ProductList.Count(); resultDocumentSet.Documents = new ResultDocument[] { }; var searchResult = new SearchResults(criteria, new ResultDocumentSet[] { resultDocumentSet }); var items = ProductList.Skip(criteria.StartingRecord).Take(criteria.RecordsToRetrieve).ToArray(); var result = new CatalogItemSearchResults(criteria, null, searchResult); return(result); }
/// <summary> /// Searches by given parameters. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="parameters">The parameters.</param> /// <returns>CatalogItemSearchModel.</returns> private CatalogItemSearchModel SearchResults(CatalogItemSearchCriteria criteria, SearchParameters parameters) { var pageNumber = parameters.PageIndex; var pageSize = parameters.PageSize; criteria.Locale = UserHelper.CustomerSession.Language; criteria.Catalog = UserHelper.CustomerSession.CatalogId; criteria.RecordsToRetrieve = pageSize; criteria.StartingRecord = (pageNumber - 1) * pageSize; criteria.Pricelists = UserHelper.CustomerSession.Pricelists; return GetModelFromCriteria(criteria, parameters); }