Skip to content

Commit

Permalink
VCST-204: Filter in Orders blade doesn't work with indexing search (#398
Browse files Browse the repository at this point in the history
)

fix: Filter in Orders blade doesn't work with indexing search (#398)
  • Loading branch information
OlegoO committed Jan 19, 2024
1 parent b2ce100 commit 0939178
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace VirtoCommerce.OrdersModule.Core.Search.Indexed
{
public interface IIndexedCustomerOrderSearchService
{
Task<CustomerOrderSearchResult> SearchCustomerOrdersAsync(CustomerOrderIndexedSearchCriteria criteria);
Task<CustomerOrderSearchResult> SearchCustomerOrdersAsync(CustomerOrderSearchCriteria criteria);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,18 +44,76 @@ protected virtual IList<IFilter> GetFilters(SearchCriteriaBase criteria)
{
var result = new List<IFilter>();

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<IFilter> GetPermanentFilters(CustomerOrderSearchCriteria criteria)
{
var result = new List<IFilter>();

if (!string.IsNullOrEmpty(criteria.Keyword))
{
var parseResult = _searchPhraseParser.Parse(criteria.Keyword);
criteria.Keyword = parseResult.Keyword;
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;
}

Expand Down
53 changes: 53 additions & 0 deletions src/VirtoCommerce.OrdersModule.Data/Search/Indexed/FilterHelper.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IndexedCustomerOrderSearchService(ISearchRequestBuilderRegistrar searchRe
_configuration = configuration;
}

public virtual async Task<CustomerOrderSearchResult> SearchCustomerOrdersAsync(CustomerOrderIndexedSearchCriteria criteria)
public virtual async Task<CustomerOrderSearchResult> SearchCustomerOrdersAsync(CustomerOrderSearchCriteria criteria)
{
if (!_configuration.IsOrderFullTextSearchEnabled())
{
Expand All @@ -46,7 +46,7 @@ public virtual async Task<CustomerOrderSearchResult> SearchCustomerOrdersAsync(C
return result;
}

protected virtual async Task<CustomerOrderSearchResult> ConvertResponseAsync(SearchResponse response, CustomerOrderIndexedSearchCriteria criteria)
protected virtual async Task<CustomerOrderSearchResult> ConvertResponseAsync(SearchResponse response, CustomerOrderSearchCriteria criteria)
{
var result = AbstractTypeFactory<CustomerOrderSearchResult>.TryCreateInstance();

Expand All @@ -59,7 +59,7 @@ protected virtual async Task<CustomerOrderSearchResult> ConvertResponseAsync(Sea
return result;
}

protected virtual async Task<IList<CustomerOrder>> ConvertDocumentsAsync(IList<SearchDocument> documents, CustomerOrderIndexedSearchCriteria criteria)
protected virtual async Task<IList<CustomerOrder>> ConvertDocumentsAsync(IList<SearchDocument> documents, CustomerOrderSearchCriteria criteria)
{
var result = new List<CustomerOrder>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public ActionResult GetOrderFullTextSearchEnabled()

[HttpPost]
[Route("indexed/search")]
public async Task<ActionResult<CustomerOrderSearchResult>> SearchCustomerOrderIndexed([FromBody] CustomerOrderIndexedSearchCriteria criteria)
public async Task<ActionResult<CustomerOrderSearchResult>> SearchCustomerOrderIndexed([FromBody] CustomerOrderSearchCriteria criteria)
{
var result = await _indexedSearchService.SearchCustomerOrdersAsync(criteria);
return Content(JsonConvert.SerializeObject(result, _outputJsonSerializerSettings), "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0939178

Please sign in to comment.