public SearchResult Search(SearchCriteria criteria) { SearchResult retVal; if (!string.IsNullOrEmpty(criteria.Keyword) && _settingsManager.GetValue("VirtoCommerce.SearchApi.UseCatalogIndexedSearchInManager", true)) { // use indexed search retVal = new SearchResult(); // TODO: create outline for category // TODO: implement sorting var serviceCriteria = new SimpleCatalogItemSearchCriteria() { RawQuery = criteria.Keyword, Catalog = criteria.CatalogId, StartingRecord = criteria.Skip, RecordsToRetrieve = criteria.Take, WithHidden = true }; SearchItems(_searchConnection.Scope, retVal, serviceCriteria, ItemResponseGroup.ItemInfo | ItemResponseGroup.Outlines); } else { // use original impl. from catalog module retVal = _catalogSearchService.Search(criteria); } return(retVal); }
public void Can_find_using_simple_search(string providerType) { var scope = _DefaultScope; var provider = GetSearchProvider(providerType, scope); SearchHelper.CreateSampleIndex(provider, scope); var criteria = new SimpleCatalogItemSearchCriteria { Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, RawQuery = "color:bLue" }; var results = provider.Search <DocumentDictionary>(scope, criteria); Assert.True(results.DocCount == 1, string.Format("Returns {0} instead of 1", results.DocCount)); var productName = results.Documents.ElementAt(0)["name"] as string; // black sox Assert.True(productName == "blue shirt"); if (providerType == "Elastic") { criteria = new SimpleCatalogItemSearchCriteria { Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, RawQuery = @"price_usd:[100 TO 199]" }; results = provider.Search <DocumentDictionary>(scope, criteria); Assert.True(results.DocCount == 1, string.Format("Returns {0} instead of 1", results.DocCount)); } criteria = new SimpleCatalogItemSearchCriteria { Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, RawQuery = @"is:priced" }; results = provider.Search <DocumentDictionary>(scope, criteria); Assert.True(results.DocCount > 0, string.Format("Returns {0} instead of >0", results.DocCount)); criteria = new SimpleCatalogItemSearchCriteria { Catalog = "goods", RecordsToRetrieve = 10, StartingRecord = 0, RawQuery = @"is:visible is:red3" }; results = provider.Search <DocumentDictionary>(scope, criteria); Assert.True(results.DocCount == 1, string.Format("Returns {0} instead of 1", results.DocCount)); }
protected virtual QueryContainer GetSimpleQuery <T>(SimpleCatalogItemSearchCriteria criteria) where T : class { QueryContainer result = null; if (criteria != null) { if (criteria.RawQuery != null && !string.IsNullOrEmpty(criteria.RawQuery)) { result = new QueryStringQuery { Query = criteria.RawQuery, Lenient = true, DefaultOperator = Operator.And, Analyzer = "standard" }; } } return(result); }