public SearchResultMessageEntity Search(string userSubcriptionToken, string queryString, IShopgunWebOperationContext shopgunWebOperationContext)
        {
            //TODO identify User
            User user = null;

            ////TODO Check for Subscription token, is valid. Maybe it this shall been done the webservice?

            SearchResultMessageEntity result;
            bool productExistsInDatabase = false;

            if (queryString.IsGtin())
            {
                Log.Debug("GTIN search for {0}", queryString);
                var product = _productApplicationService.FindProductByGtin(queryString, true);
                //var product = _productApplicationService.FindProductByGtinInOwnDatabase(queryString, true);

                result = new SearchResultMessageEntity();
                if (!string.IsNullOrEmpty(product.ProductName))
                {
                    result.SearchType = SearchResultMessageEntity.GtinSearch;
                    result.Products   = new List <Product> {
                        product
                    };
                }
                else if (product.Brand != null)
                {
                    if (!string.IsNullOrEmpty(product.Brand.BrandName))
                    {
                        result.SearchType = SearchResultMessageEntity.FreeSearch;
                        result.Brands     = new List <Brand> {
                            product.Brand
                        };
                    }
                    else if (product.Brand.Owner != null)
                    {
                        result.SearchType = SearchResultMessageEntity.FreeSearch;
                        result.Companies  = new List <Company> {
                            product.Brand.Owner
                        };
                    }
                }
                if (product.Id > 0)
                {
                    productExistsInDatabase = true;
                }
            }
            else
            {
                Log.Debug("Freetext search for \"{0}\"", queryString);
                result =
                    new SearchResultMessageEntity
                {
                    SearchType = SearchResultMessageEntity.FreeSearch
                    ,
                    //Brands = _brandApplicationService.FindBrands(queryString, true)
                    //,
                    //Companies = _companyApplicationService.FindCompanies(queryString, true)
                    //,
                    //Concepts = _conceptApplicationService.FindConcepts(queryString, true)
                    //,
                    //Countries = _countryApplicationService.FindCountries(queryString, true)
                    //,
                    //Ingredients = _ingredientApplicationService.FindIngredients(queryString, true, true)
                };
                //Only exact match for now...
                var ingredient = _ingredientApplicationService.FindIngredient(queryString, true, true);
                if (ingredient != null)
                {
                    result.Ingredients = new List <Ingredient> {
                        ingredient
                    };
                }
                var company = _companyApplicationService.FindCompany(queryString, true);
                if (ingredient == null && company != null)
                {
                    result.Companies = new List <Company> {
                        company
                    };
                    result.SearchType = SearchResultMessageEntity.FreeSearch;
                }

                //if (!result.HasResults())
                //{
                //    result.Products = _productDomainService.FindProducts(queryString, true);
                //}
            }
            var resultFound = result.HasResults();

            if (shopgunWebOperationContext != null)
            {
                var userAgent = shopgunWebOperationContext.UserAgent;
                var imei      = shopgunWebOperationContext.IMEI;
                var model     = shopgunWebOperationContext.Model;
                var osVersion = shopgunWebOperationContext.OsVersion;

                _adviceSearchStatisticsDomainService.AddAdviceSearch(user, queryString, userAgent, imei, model, resultFound, osVersion);
            }

            if (result.SearchType != SearchResultMessageEntity.GtinSearch || productExistsInDatabase)
            {
                //_statisticsDomainService.AddStatistics(user, result, userAgent, imei, model, osVersion);
            }

            return(result);
        }
Ejemplo n.º 2
0
 public void AddAdviceSearchTest()
 {
     _adviceSearchStatisticsDomainService.AddAdviceSearch(null, Platforms.Unknown, "moep");
 }