Пример #1
0
        public IActionResult GetProductsByBrandId(Guid brandId, [FromQuery] ProductSearchParams productSearchParams)
        {
            Brand brand = _repository.GetBrandById(brandId);

            if (brand == null)
            {
                return(NotFound());
            }

            if (productSearchParams == null)
            {
                return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(_repository.GetProductsOfBrand(brandId))));
            }

            var productsOfBrandQuery = _repository.GetProductsOfBrandWithParams(brandId, productSearchParams);

            if (productSearchParams.Fields == null)
            {
                return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(productsOfBrandQuery)));
            }

            List <ExpandoObject> list = new List <ExpandoObject>();

            foreach (Product product in productsOfBrandQuery)
            {
                ProductReadDto pr = _mapper.Map <ProductReadDto>(product);
                list.Add(pr.ShapeData(productSearchParams.Fields));
            }

            return(Ok(list));
        }
Пример #2
0
        // [END vision_product_search_get_similar_products]

        // [START vision_product_search_get_similar_products_gcs]
        private static int GetSimilarProductsGcs(GetSimilarProductsGcsOptions opts)
        {
            // Create annotate image request along with product search feature.
            Image image = Image.FromUri(opts.GcsUri);
            var   imageAnnotatorClient = ImageAnnotatorClient.Create();

            // Product Search specific parameters
            var productSearchParams = new ProductSearchParams
            {
                ProductSetAsProductSetName = new ProductSetName(opts.ProjectID,
                                                                opts.ComputeRegion,
                                                                opts.ProductSetId),
                ProductCategories = { opts.ProductCategory },
                Filter            = opts.Filter
            };

            // Search products similar to the image.
            var results = imageAnnotatorClient.DetectSimilarProducts(image, productSearchParams);

            Console.WriteLine("Similar products:");
            foreach (var result in results.Results)
            {
                var product = result.Product;
                Console.WriteLine($"Score (Confidence): {result.Score}");
                Console.WriteLine($"Image name: {result.Image}");
                Console.WriteLine($"Product name: {product.Name}");
                Console.WriteLine($"Product display name: {product.DisplayName}");
                Console.WriteLine($"Product description: {product.Description}");
                Console.WriteLine($"Product labels: {product.ProductLabels}");
            }
            return(0);
        }
Пример #3
0
 public async Task <List <Product> > GetAll(ProductSearchParams productSearchParams)
 {
     return(await _context.Set <Product>().Where(x =>
                                                 (string.IsNullOrEmpty(productSearchParams.Description) || x.Description.Contains(productSearchParams.Description)) &&
                                                 (!productSearchParams.CategoryId.HasValue || x.CategoryId == productSearchParams.CategoryId)
                                                 ).ToListAsync());
 }
Пример #4
0
        public string GetSimilar()
        {
            var client = InstantiatedImageAnnotatorClient.GetClient();
            var path   = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");

            Image image = Image.FromFile($"{path}\\maddoggy.jpg");
            var   opts  = new GetSimilarProductsOptions()
            {
                ComputeRegion   = "europe-west1",
                ProjectID       = "ninth-terminal-245420",
                ProductSetId    = "1",
                Filter          = "",
                ProductCategory = "packagedgoods-v1",
            };

            var productSearchParams = new ProductSearchParams
            {
                ProductSetAsProductSetName = new ProductSetName(opts.ProjectID,
                                                                opts.ComputeRegion,
                                                                opts.ProductSetId),
                ProductCategories = { opts.ProductCategory },
                Filter            = opts.Filter
            };

            // Search products similar to the image.
            var results = client.DetectSimilarProducts(image, productSearchParams);

            return(JsonConvert.SerializeObject(results));
        }
Пример #5
0
        public IEnumerable <Product> GetProductsOfBrandWithParams(Guid brandId, ProductSearchParams productSearchParams)
        {
            Brand brand = _db.Brand.FirstOrDefault(b => b.Id == brandId);

            if (brand == null)
            {
                throw new ArgumentNullException(nameof(brand));
            }

            if (productSearchParams == null)
            {
                throw new ArgumentNullException(nameof(productSearchParams));
            }

            IQueryable <Product> productsToReturn = _db.Product.Where(p => p.BrandId == brandId);

            if (string.IsNullOrWhiteSpace(productSearchParams.Category) &&
                string.IsNullOrWhiteSpace(productSearchParams.SearchQuery) && string.IsNullOrWhiteSpace(productSearchParams.OrderBy))
            {
                return(productsToReturn.ToList());
            }


            if (!string.IsNullOrWhiteSpace(productSearchParams.Category))
            {
                productsToReturn = productsToReturn.Where(p =>
                                                          p.Category.ToLower().Trim() == productSearchParams.Category.ToLower().Trim());
            }

            if (!string.IsNullOrWhiteSpace(productSearchParams.SearchQuery))
            {
                string query = productSearchParams.SearchQuery.Trim();
                productsToReturn = productsToReturn.Where(p =>
                                                          p.Category.Contains(query) || p.Description.Contains(query) || p.Name.Contains(query));
            }

            if (!string.IsNullOrWhiteSpace(productSearchParams.OrderBy))
            {
                //productsToReturn = productsToReturn.Sort(productSearchParams.OrderBy);
                string   orderType = " ascending";
                string[] query     = productSearchParams.OrderBy.Split(',');
                if (query.Length > 1)
                {
                    switch (query[1].ToLower().Trim())
                    {
                    case "desc":
                        orderType = " descending";
                        break;
                    }
                }

                productsToReturn = productsToReturn.OrderBy(query[0].Trim() + orderType);
            }

            return(productsToReturn.ToList());
        }
Пример #6
0
        public IReadOnlyList <ProductDto> Execute(ProductSearchParams search)
        {
            var data = _context.Read();

            if (!search.Name.IsTotalyEmpty())
            {
                data = data.Where(p => p.Name.Contains(search.Name));
            }

            if (search.Order != null)
            {
                data = search.Order == SortOrder.Ascending ?
                       data.OrderBy(x => x.Name) :
                       data.OrderByDescending(x => x.Name);
            }

            return(data.ToList());
        }
        private async Task <TargetSearchResults> GetSimilarProductsFile(ImageAnnotatorClient imageAnnotatorClient, GetSimilarProductsOptions opts)
        {
            // Create annotate image request along with product search feature.
            Image image = Image.FromBytes(opts.ImageBinaries);

            // Product Search specific parameters
            var productSearchParams = new ProductSearchParams
            {
                ProductSetAsProductSetName = new ProductSetName(opts.ProjectID,
                                                                opts.ComputeRegion,
                                                                opts.ProductSetId),
                ProductCategories = { opts.ProductCategory },
                Filter            = opts.Filter
            };

            // Search products similar to the image.
            ProductSearchResults results = await imageAnnotatorClient.DetectSimilarProductsAsync(image, productSearchParams);

            return(this.mapper.Map <TargetSearchResults>(results));
        }
Пример #8
0
        public IReadOnlyList <ProductDto> Execute(ProductSearchParams search)
        {
            var query = _context.Products.AsQueryable();

            if (!search.Name.IsTotalyEmpty())
            {
                query = query.Where(p => p.Name.Contains(search.Name));
            }

            if (search.Order != null)
            {
                query = search.Order == SortOrder.Ascending ?
                        query.OrderBy(x => x.Name) :
                        query.OrderByDescending(x => x.Name);
            }

            query = query.Include(p => p.Category)
                    .Include(p => p.Manufacturer)
                    .Include(p => p.Supplier);

            return(_mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(query.ToList()));
        }
Пример #9
0
        public async Task <List <ProductSearchResult> > GetSimilarAsync(byte[] base64Image)
        {
            var client        = _clientFactory.CreateImageAnnotatorClient();
            var productClient = _clientFactory.CreateProductSearchClient();

            Image image = Image.FromBytes(base64Image);

            var productSearchParams = new ProductSearchParams
            {
                ProductSetAsProductSetName = new ProductSetName(_projectInfo.ProjectID,
                                                                _projectInfo.ComputeRegion,
                                                                "1"),
                ProductCategories = { "packagedgoods-v1" },
                Filter            = ""
            };

            // Search products similar to the image.
            var detectSimilar = await client.DetectSimilarProductsAsync(image, productSearchParams);

            var mapped = detectSimilar.Results.Select(async x =>
            {
                var item = new ProductSearchResult()
                {
                    Score       = x.Score,
                    ProductName = x.Product.Name.Split("/").Last(),
                };

                if (x.Score > 0.6)
                {
                    item.ReferenceImages = (await ListReferenceImagesOfProduct(productClient, item.ProductName)).ToList();
                }
                return(item);
            }).ToList();

            var results = await Task.WhenAll(mapped);

            return(results.ToList());
        }
Пример #10
0
 public async Task <IActionResult> Get([FromQuery] ProductSearchParams productSearchParams)
 {
     return(Ok(await _productService.GetAll(productSearchParams)));
 }
Пример #11
0
 public async Task <List <Product> > GetAll(ProductSearchParams productSearchParams)
 {
     return(await _productRepository.GetAll(productSearchParams));
 }
Пример #12
0
 public IActionResult Index(ProductSearchParams search)
 {
     return(View(_executor.ExecuteQuery(_query, search)));
 }