示例#1
0
		public async Task<IEnumerable<IStore>> FetchStores(int pageSize, int offset, IStoreFilter filter = null)
		{
			using (var tokenSource = new CancellationTokenSource(Constants.FetchStoresTimeout))
			{
				var result = await FindStores("", pageSize, offset, filter);
				return result;
			}
		}
示例#2
0
		public async Task<int> CountStores(string query, IStoreFilter filter = null)
		{
			var algoliaQuery = new Algolia.Search.Query(query);
			algoliaQuery = getFilteredStoreQuery(algoliaQuery, filter);
			algoliaQuery.SetNbHitsPerPage(0);
			var result = await _storeIndex.SearchAsync(algoliaQuery);
			try
			{
				var count = result["nbHits"].ToObject<int>();
				return count;
			}
			catch
			{
			}
			return -1;
		}
示例#3
0
		public async Task<IEnumerable<IStore>> FindStores(string query, int pageSize, int offset, IStoreFilter filter = null)
		{
			using (var tokenSource = new CancellationTokenSource(Constants.FindStoresTimeout))
			{
				var algoliaQuery = new Algolia.Search.Query(query);
				algoliaQuery = getFilteredStoreQuery(algoliaQuery, filter);
				if (pageSize > 0)
				{
					algoliaQuery.SetNbHitsPerPage(pageSize);
				}
				if (offset > 0)
				{
					algoliaQuery.SetPage(offset / pageSize);
				}
				var result = await _storeIndex.SearchAsync(algoliaQuery, tokenSource.Token);
				var stores = result["hits"].ToObject<List<Store>>();
				return stores;
			}
		}
示例#4
0
		private async Task<Dictionary<string, int>> getStoreAttributeFacets(string query, string facetAttribute, IStoreFilter filter = null, params string[] childFacets)
		{
			var algoliaQuery = new Algolia.Search.Query(query);
			algoliaQuery = getFilteredStoreQuery(algoliaQuery, filter, new string[] {facetAttribute}.Concatenate(childFacets));
			algoliaQuery.SetNbHitsPerPage(0);
			algoliaQuery.SetFacets(new string[] {facetAttribute});
			var result = await _storeIndex.SearchAsync(algoliaQuery);
			try
			{
				var facets = result["facets"][facetAttribute].ToObject<Dictionary<string, int>>();
				return facets;
			}
			catch
			{
			}
			return null;
		}
示例#5
0
		private Algolia.Search.Query getFilteredStoreQuery(Algolia.Search.Query query, IStoreFilter filter, params string[] excludeFacets)
		{
			if (filter != null)
			{
				List<string> facets = new List<string>();
				facets.Add("isBlocked:false");
				if (filter.Category != null && !excludeFacets.Contains("categoryID"))
				{
					facets.Add("categoryID:"+filter.Category.ID);
				}

				if (filter.Country != null && !excludeFacets.Contains("countryID"))
				{
					facets.Add("countryID:"+filter.Country.ID);
				}

				if (filter.City != null && !excludeFacets.Contains("cityID"))
				{
					facets.Add("cityID:"+filter.City.ID);
				}

				if (facets.Count > 0)
					query.SetFacetFilters(facets);

				if (filter.Tags != null && filter.Tags.Count > 0)
				{
					query.SetTagFilters(string.Join(",", filter.Tags));
				}
			}
			return query;
		}
示例#6
0
		private ParseQuery<ParseStore> getFilteredStoreQuery(ParseQuery<ParseStore> query, IStoreFilter filter)
		{
			if (filter != null)
			{
				if (filter.Category != null)
				{
					query = query.Where(s => s.Category == ParseObject.CreateWithoutData<ParseStoreCategory>(filter.Category.ID));
				}

				if (filter.Country != null)
				{
					query = query.Where(s => s.Country == ParseObject.CreateWithoutData<ParseCountry>(filter.Country.ID));
				}

				if (filter.City != null)
				{
					query = query.Where(s => s.City == ParseObject.CreateWithoutData<ParseCity>(filter.City.ID));
				}

				if (filter.Tags != null && filter.Tags.Count > 0)
				{
					query = getContainsAllQuery(query, "tags", filter.Tags);
				}
			}
			return query;
		}
示例#7
0
		public async Task<Dictionary<string, int>> GetStoreCityFacets(string query, IStoreFilter filter = null)
		{
			var result = await getStoreAttributeFacets(query, "cityID", filter);
			return result;
		}
		public StoreFilterChangedMessage(object sender, IStoreFilter productFilter)
			: base(sender)
		{
			StoreFilter = productFilter;
		}