예제 #1
0
        public IActionResult QuickKeywordSearch([FromBody] QuickSearchModel searchModel)
        {
            if (searchModel == null ||
                String.IsNullOrWhiteSpace(searchModel.keywords) ||
                searchModel.keywords.Length < _settings.MinimumKeywordSearchLength)
            {
                return(new StatusCodeResult(400));
            }

            KeywordSearchOptions searchOptions = new KeywordSearchOptions(IsUserLoggedIn(), searchModel.keywords, true);

            List <SearchResponseItem> searchResults = _searchProvider.KeywordSearch(searchOptions);

            IEnumerable <SearchResponseItem> topResults = searchResults.OrderByDescending(r => r.Relevance).Take(5);

            if (_settings.HighlightQuickSearchTerms)
            {
                foreach (SearchResponseItem item in topResults)
                {
                    item.HighlightKeywords(searchModel.keywords.Length);
                }
            }

            return(new JsonResult(topResults)
            {
                StatusCode = 200,
                ContentType = "application/json"
            });
        }
        public void NormalSearchFindAllKeywordProdALoggedOutSavedToMemory()
        {
            KeywordSearchOptions keywordSearchOptions = new KeywordSearchOptions(false, "PrODA", false, true);

            string cacheName = String.Format("Keyword Search {0} {1} {2} {3} {4} {5}",
                                             keywordSearchOptions.IsLoggedIn, keywordSearchOptions.ExactMatch,
                                             keywordSearchOptions.MaximumSearchResults, keywordSearchOptions.Timeout,
                                             keywordSearchOptions.SearchTerm, keywordSearchOptions.QuickSearch);


            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginDocs) as IPluginClassesService;

            Assert.IsNotNull(pluginServices);

            List <ISearchProvider> searchProviders = pluginServices.GetPluginClasses <ISearchProvider>();

            Assert.AreEqual(1, searchProviders.Count);
            IMemoryCache memoryCache = _testPluginDocs.GetRequiredService <IMemoryCache>();

            memoryCache.GetCache().Clear();
            Assert.IsNull(memoryCache.GetCache().Get(cacheName));

            List <SearchResponseItem> results = searchProviders[0].KeywordSearch(keywordSearchOptions);


            Assert.AreEqual(1, results.Count);

            DefaultSearchProvider defaultSearchProvider = (DefaultSearchProvider)searchProviders[0];

            Assert.IsNotNull(defaultSearchProvider.GetCacheManager.Get(cacheName));
        }
예제 #3
0
        public void EnsurePropertiesDictionaryCreated()
        {
            KeywordSearchOptions options = new KeywordSearchOptions(false, "test");

            Assert.IsNotNull(options.Properties);
        }
예제 #4
0
 public void KeywordLoggedOutInvalidSearchTermEmptyString()
 {
     KeywordSearchOptions options = new KeywordSearchOptions(false, "");
 }
예제 #5
0
 public void KeywordLoggedOutInvalidSearchTermNull()
 {
     KeywordSearchOptions options = new KeywordSearchOptions(false, null);
 }
예제 #6
0
 public void KeywordLoggedOutValidSearchTerm()
 {
     KeywordSearchOptions options = new KeywordSearchOptions(false, "test");
 }
예제 #7
0
 public void KeywordLoggedInValidSearchTerm()
 {
     KeywordSearchOptions options = new KeywordSearchOptions(true, "test");
 }
        public IActionResult AdvancedSearch(ProductSearchViewModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(Redirect($"/Search/Advanced/{LanguageStrings.Products}/"));
            }

            GetSearchId(model);

            KeywordSearchProvider searchProvider = new KeywordSearchProvider(_productProvider);

            KeywordSearchOptions options = new KeywordSearchOptions(model.SearchText ?? String.Empty)
            {
                MaximumSearchResults = Constants.MaximumProducts
            };

            GetSearchId(model);
            options.SearchName = model.SearchName;

            // add additional search options
            foreach (CheckedViewItemModel item in model.ProductGroups)
            {
                if (item.Selected)
                {
                    options.Properties.Add(item.Name, KeywordSearchProvider.ProductGroup);
                }
            }

            List <ProductPriceInfo> prices      = new List <ProductPriceInfo>();
            List <ProductPriceInfo> priceGroups = GetPriceGroups();

            foreach (CheckedViewItemModel item in model.Prices)
            {
                if (item.Selected)
                {
                    ProductPriceInfo priceGroup = priceGroups.Where(pg => pg.Text.Equals(item.Name)).FirstOrDefault();

                    if (priceGroup != null)
                    {
                        prices.Add(priceGroup);
                    }
                }
            }

            if (prices.Count == 0)
            {
                prices.AddRange(priceGroups);
            }

            options.Properties.Add(KeywordSearchProvider.Price, prices);

            if (model.ContainsVideo)
            {
                options.Properties.Add(KeywordSearchProvider.ContainsVideo, true);
            }

            // perform the search, the results will be held in memory and shown on search page
            DefaultSearchThread.KeywordSearch(searchProvider, options);

            string cacheName = $"Product Search View Model {model.SearchName}";

            _memoryCache.GetExtendingCache().Add(cacheName, new CacheItem(cacheName, model), true);

            return(Redirect($"/Search/Advanced/{LanguageStrings.Products}/{model.SearchName}/"));
        }