diff --git a/src/VirtoCommerce.OrdersModule.Core/Model/Search/CustomerOrderIndexedSearchCriteria.cs b/src/VirtoCommerce.OrdersModule.Core/Model/Search/CustomerOrderIndexedSearchCriteria.cs index 2e1dcdeb..4014ce96 100644 --- a/src/VirtoCommerce.OrdersModule.Core/Model/Search/CustomerOrderIndexedSearchCriteria.cs +++ b/src/VirtoCommerce.OrdersModule.Core/Model/Search/CustomerOrderIndexedSearchCriteria.cs @@ -1,7 +1,9 @@ +using System; using VirtoCommerce.Platform.Core.Common; namespace VirtoCommerce.OrdersModule.Core.Model.Search { + [Obsolete("Use CustomerOrderSearchCriteria", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")] public class CustomerOrderIndexedSearchCriteria : SearchCriteriaBase { } diff --git a/src/VirtoCommerce.OrdersModule.Core/Search/Indexed/IIndexedCustomerOrderSearchService.cs b/src/VirtoCommerce.OrdersModule.Core/Search/Indexed/IIndexedCustomerOrderSearchService.cs index a309789f..3f0043ba 100644 --- a/src/VirtoCommerce.OrdersModule.Core/Search/Indexed/IIndexedCustomerOrderSearchService.cs +++ b/src/VirtoCommerce.OrdersModule.Core/Search/Indexed/IIndexedCustomerOrderSearchService.cs @@ -5,6 +5,6 @@ namespace VirtoCommerce.OrdersModule.Core.Search.Indexed { public interface IIndexedCustomerOrderSearchService { - Task SearchCustomerOrdersAsync(CustomerOrderIndexedSearchCriteria criteria); + Task SearchCustomerOrdersAsync(CustomerOrderSearchCriteria criteria); } } diff --git a/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/CustomerOrderSearchRequestBuilder.cs b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/CustomerOrderSearchRequestBuilder.cs index 375b3c04..83d51971 100644 --- a/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/CustomerOrderSearchRequestBuilder.cs +++ b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/CustomerOrderSearchRequestBuilder.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using VirtoCommerce.OrdersModule.Core; +using VirtoCommerce.OrdersModule.Core.Model.Search; using VirtoCommerce.Platform.Core.Common; using VirtoCommerce.SearchModule.Core.Extensions; using VirtoCommerce.SearchModule.Core.Model; @@ -43,6 +44,25 @@ protected virtual IList GetFilters(SearchCriteriaBase criteria) { var result = new List(); + if (criteria.ObjectIds?.Any() == true) + { + result.Add(new IdsFilter { Values = criteria.ObjectIds }); + } + + if (criteria is CustomerOrderSearchCriteria orderSearchCriteria) + { + result.AddRange(GetPermanentFilters(orderSearchCriteria)); + } + + return result; + } + + + + protected virtual IList GetPermanentFilters(CustomerOrderSearchCriteria criteria) + { + var result = new List(); + if (!string.IsNullOrEmpty(criteria.Keyword)) { var parseResult = _searchPhraseParser.Parse(criteria.Keyword); @@ -50,11 +70,50 @@ protected virtual IList GetFilters(SearchCriteriaBase criteria) result.AddRange(parseResult.Filters); } - if (criteria.ObjectIds?.Any() == true) + if (criteria.ObjectIds != null) { result.Add(new IdsFilter { Values = criteria.ObjectIds }); } + if (!criteria.StoreIds.IsNullOrEmpty()) + { + result.Add(FilterHelper.CreateTermFilter("storeid", criteria.StoreIds)); + } + + if (!criteria.Statuses.IsNullOrEmpty()) + { + result.Add(FilterHelper.CreateTermFilter("status", criteria.Statuses)); + } + + if (criteria.StartDate.HasValue && criteria.EndDate.HasValue) + { + result.Add(FilterHelper.CreateDateRangeFilter("createddate", criteria.StartDate, null, true, true)); + } + else if (criteria.StartDate.HasValue) + { + result.Add(FilterHelper.CreateDateRangeFilter("createddate", criteria.StartDate, null, true, true)); + } + else if (criteria.EndDate.HasValue) + { + result.Add(FilterHelper.CreateDateRangeFilter("createddate", null, criteria.EndDate, true, true)); + } + + if (!criteria.CustomerIds.IsNullOrEmpty()) + { + result.Add(FilterHelper.CreateTermFilter("customerid", criteria.CustomerIds)); + } + + if (!string.IsNullOrEmpty(criteria.EmployeeId)) + { + result.Add(FilterHelper.CreateTermFilter("employeeid", criteria.EmployeeId)); + } + + if (!criteria.WithPrototypes) + { + result.Add(FilterHelper.CreateTermFilter("isprototype", "false")); + } + + return result; } diff --git a/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/FilterHelper.cs b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/FilterHelper.cs new file mode 100644 index 00000000..065c96f7 --- /dev/null +++ b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/FilterHelper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using VirtoCommerce.SearchModule.Core.Model; + +namespace VirtoCommerce.OrdersModule.Data.Search.Indexed +{ + public static class FilterHelper + { + public static IFilter CreateTermFilter(string fieldName, string value) + { + return new TermFilter + { + FieldName = fieldName, + Values = new[] { value }, + }; + } + + public static IFilter CreateTermFilter(string fieldName, IEnumerable values) + { + return new TermFilter + { + FieldName = fieldName, + Values = values.ToArray(), + }; + } + + public static IFilter CreateDateRangeFilter(string fieldName, DateTime? lower, DateTime? upper, bool includeLower, bool includeUpper) + { + return CreateRangeFilter(fieldName, lower?.ToString("O"), upper?.ToString("O"), includeLower, includeUpper); + } + + public static IFilter CreateRangeFilter(string fieldName, string lower, string upper, bool includeLower, bool includeUpper) + { + return new RangeFilter + { + FieldName = fieldName, + Values = new[] { CreateRangeFilterValue(lower, upper, includeLower, includeUpper) }, + }; + } + + public static RangeFilterValue CreateRangeFilterValue(string lower, string upper, bool includeLower, bool includeUpper) + { + return new RangeFilterValue + { + Lower = lower, + Upper = upper, + IncludeLower = includeLower, + IncludeUpper = includeUpper, + }; + } + } +} diff --git a/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/IndexedCustomerOrderSearchService.cs b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/IndexedCustomerOrderSearchService.cs index 39336409..ec122e2b 100644 --- a/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/IndexedCustomerOrderSearchService.cs +++ b/src/VirtoCommerce.OrdersModule.Data/Search/Indexed/IndexedCustomerOrderSearchService.cs @@ -30,7 +30,7 @@ public IndexedCustomerOrderSearchService(ISearchRequestBuilderRegistrar searchRe _configuration = configuration; } - public virtual async Task SearchCustomerOrdersAsync(CustomerOrderIndexedSearchCriteria criteria) + public virtual async Task SearchCustomerOrdersAsync(CustomerOrderSearchCriteria criteria) { if (!_configuration.IsOrderFullTextSearchEnabled()) { @@ -46,7 +46,7 @@ public virtual async Task SearchCustomerOrdersAsync(C return result; } - protected virtual async Task ConvertResponseAsync(SearchResponse response, CustomerOrderIndexedSearchCriteria criteria) + protected virtual async Task ConvertResponseAsync(SearchResponse response, CustomerOrderSearchCriteria criteria) { var result = AbstractTypeFactory.TryCreateInstance(); @@ -59,7 +59,7 @@ protected virtual async Task ConvertResponseAsync(Sea return result; } - protected virtual async Task> ConvertDocumentsAsync(IList documents, CustomerOrderIndexedSearchCriteria criteria) + protected virtual async Task> ConvertDocumentsAsync(IList documents, CustomerOrderSearchCriteria criteria) { var result = new List(); diff --git a/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs b/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs index d68fdc49..75a2ae84 100644 --- a/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs +++ b/src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs @@ -716,7 +716,7 @@ public ActionResult GetOrderFullTextSearchEnabled() [HttpPost] [Route("indexed/search")] - public async Task> SearchCustomerOrderIndexed([FromBody] CustomerOrderIndexedSearchCriteria criteria) + public async Task> SearchCustomerOrderIndexed([FromBody] CustomerOrderSearchCriteria criteria) { var result = await _indexedSearchService.SearchCustomerOrdersAsync(criteria); return Content(JsonConvert.SerializeObject(result, _outputJsonSerializerSettings), "application/json"); diff --git a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/customerOrder-list.js b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/customerOrder-list.js index 63799ec3..c5030d9e 100644 --- a/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/customerOrder-list.js +++ b/src/VirtoCommerce.OrdersModule.Web/Scripts/blades/customerOrder-list.js @@ -72,7 +72,11 @@ function ($rootScope, $scope, $localStorage, customerOrders, bladeUtils, dialogS angular.extend(criteria, filter.current); } - var endpoint = $scope.useIndexedSearch ? customerOrders.indexedSearch : customerOrders.search; + var endpoint = customerOrders.search; + + if ($scope.useIndexedSearch && (criteria.keyword || filter.current)) { + endpoint = customerOrders.indexedSearch; + } endpoint(criteria, function (data) { blade.isLoading = false;