예제 #1
0
        public IActionResult SaveSearchTerm(SearchTermModel searchTermModel)
        {
            var searchTerm = searchTermModel.Id > 0 ? _searchTermService.Get(searchTermModel.Id) : new SearchTerm();

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

            _modelMapper.Map(searchTermModel, searchTerm);
            _searchTermService.InsertOrUpdate(searchTerm);

            return(R.Success.With("id", searchTerm.Id).Result);
        }
예제 #2
0
        public IActionResult GetAutoCompleteResults([FromQuery] SearchModel searchModel)
        {
            if (searchModel == null || searchModel.Term.IsNullEmptyOrWhiteSpace())
            {
                return(R.Success.With("products", null).With("terms", null).With("totalProducts", 0).Result);
            }

            var term        = searchModel.Term;
            var searchTerms = _searchTermService.Get(out _, x => x.Term.StartsWith(term), x => x.Score, RowOrder.Descending, count: _searchPlusSettings.NumberOfAutoCompleteResults).ToList();
            //matching products
            var products = _productService.Get(out var totalProducts, x => x.Name.Contains(term),
                                               x => x.PopularityIndex,
                                               RowOrder.Descending, 1, _searchPlusSettings.NumberOfAutoCompleteResults).ToList();

            var productsModel = products.Select(_searchTermModelFactory.Create).ToList();
            var termsModel    = searchTerms.Select(_searchTermModelFactory.Create).ToList();

            return(R.Success.With("products", productsModel).With("terms", termsModel)
                   .With("totalProducts", totalProducts).Result);
        }