Example #1
0
 private void CheckQuery(BoostedSearchQuery query)
 {
     if (String.IsNullOrEmpty(query.Query) || query.SearchableFields.Count == 0)
     {
         throw new ArgumentException(SearchServiceResources.IncorrectQueryStr);
     }
 }
        public void Search_EmptyQuery_Return_ArgumentException()
        {
            mockRepo.Setup(x => x.GetAll <TestUser>(It.IsAny <string>(), It.IsAny <string[]>(), It.IsAny <int>())).Returns(users);

            var query = new BoostedSearchQuery();

            Assert.Throws <ArgumentException>(() => sut.Search <TestUser>(query));
        }
Example #3
0
        public IEnumerable <UserQuery> GetSimilarQueries(string query)
        {
            var userQuery = new BoostedSearchQuery(query);

            userQuery.AddField("QueryString", 1.0f);
            CheckQuery(userQuery);
            return(_repository.GetAll <UserQuery>(userQuery.Query, userQuery.SearchableFields, userQuery.BoostValues, MAX_SIMILAR_QUERIES_COUNT));
        }
Example #4
0
        public async Task <IHttpActionResult> GetProducts(BoostedSearchQuery query)
        {
            var products = await _searchService.SearchProductAsync(query);

            if (products.Any())
            {
                return(Ok(products));
            }
            else
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
            }
        }
Example #5
0
        /// <summary>
        /// Performs search in repository
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="query">BoostedSearchQuery object containing query information</param>
        /// <returns></returns>
        public IEnumerable <TEntity> Search <TEntity>(BoostedSearchQuery query) where TEntity : class
        {
            CheckQuery(query);
            var similarQueries  = this.GetSimilarQueries(query.Query);
            var coincidentQuery = similarQueries.FirstOrDefault(t => t.QueryString.Equals(query.Query, StringComparison.InvariantCultureIgnoreCase));

            if (coincidentQuery == null)
            {
                UserQuery userQuery = new UserQuery();
                userQuery.QueryString = query.Query;
                _repository.Insert(userQuery);
            }
            return(_repository.GetAll <TEntity>(query.Query, query.SearchableFields, query.BoostValues, MaxResultCount));
        }
Example #6
0
        public async Task <IHttpActionResult> GetProductsDefaultFields([FromUri] string query)
        //public async Task<IEnumerable<Product>> GetProductsDefaultFields([FromUri]string query)
        {
            BoostedSearchQuery searchQuery = new BoostedSearchQuery();

            searchQuery.AddField(DEFAULT_PRODUCT_NAME_FIELD, 1.0f)
            .AddField(DEFAULT_PRODUCT_BARCODE_FIELD, 1.0f);
            //.AddField(DEFAULT_PRODUCT_COMPOSITION_FIELD, 1.0f);
            searchQuery.Query = query;

            var products = await _searchService.SearchProductAsync(searchQuery);

            if (products.Any())
            {
                return(Ok(products));
            }
            else
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
            }
        }
Example #7
0
        public IEnumerable <Product> SearchProduct(BoostedSearchQuery query)
        {
            var productDbList = Search <ProductDB>(query);

            //TODO: map all values in productDbList to Product
            List <Product> result = new List <Product>();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new Mappings.SearchProfile());
            });

            var mapper = (new Mapper(config)).DefaultContext.Mapper;

            foreach (var productDb in productDbList)
            {
                result.Add(mapper.Map <Product>(productDb));
            }

            return(result);
        }
Example #8
0
 public IEnumerable <TEntity> SearchDefault <TEntity>(BoostedSearchQuery query)
 {
     throw new NotImplementedException();
 }
Example #9
0
 public async Task <IEnumerable <Product> > SearchProductAsync(BoostedSearchQuery query)
 {
     return(await Task.Run(() => SearchProduct(query)));
 }