Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-204: Filter in Orders blade doesn't work with indexing search #398

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading