From c8121910a84183d2f8b47325c2bfea8e6624f976 Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Fri, 16 Jun 2023 07:54:54 -0700 Subject: [PATCH 1/2] Hacky fix for commodity fuzzy search Need both fuzzy and not in case they paste in the ID --- Purchasing.Core/Services/IndexSearchService.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Purchasing.Core/Services/IndexSearchService.cs b/Purchasing.Core/Services/IndexSearchService.cs index cf147e210..479cd7ee6 100644 --- a/Purchasing.Core/Services/IndexSearchService.cs +++ b/Purchasing.Core/Services/IndexSearchService.cs @@ -137,7 +137,19 @@ public IList SearchCommodities(string searchTerm) var results = _client.Search( s => s.Index(index).Query(q => q.QueryString(qs => qs.Query(searchTerm)))); - return results.Hits.Select(h => new IdAndName(h.Source.Id, h.Source.Name)).ToList(); + //Do a fuzzy search on the name field + var results1 = _client.Search( + a => a.Index(index).Query(q => q.Fuzzy(f => f.Value(searchTerm).Field("name")))); + + //join the results with distinct values + var temp = results.Hits.Select(h => new IdAndName(h.Source.Id, h.Source.Name)).ToList(); + var temp2 = results1.Hits.Select(h => new IdAndName(h.Source.Id, h.Source.Name)).ToList(); + //join temp and temp2 into a distinct list based on Id + var combinedResults = temp.Concat(temp2).GroupBy(x => x.Id).Select(x => x.First()).ToList(); //union wasn't working for some reason + + return combinedResults; + + //return results.Hits.Select(h => new IdAndName(h.Source.Id, h.Source.Name)).ToList(); } public IList SearchVendors(string searchTerm) From a742829b0d49424a9f23386af4ddd4b223ec95e1 Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Fri, 16 Jun 2023 09:53:50 -0700 Subject: [PATCH 2/2] Search AE directly --- .../Services/AggieEnterpriseService.cs | 38 +++++++++++++++++++ Purchasing.Mvc/Controllers/AjaxController.cs | 9 +++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Purchasing.Core/Services/AggieEnterpriseService.cs b/Purchasing.Core/Services/AggieEnterpriseService.cs index 1760dc819..3146b3181 100644 --- a/Purchasing.Core/Services/AggieEnterpriseService.cs +++ b/Purchasing.Core/Services/AggieEnterpriseService.cs @@ -25,6 +25,7 @@ public interface IAggieEnterpriseService Task LookupOrderStatus(string requestId); Task GetPurchasingCategories(); + Task SearchCommodities(string query); Task GetUnitOfMeasures(); Task> SearchSupplier(string query); @@ -413,6 +414,43 @@ public async Task GetPurchasingCategories() }).ToArray(); } + public async Task SearchCommodities(string query) + { + var _aggieClient = GetClient(); + + var filter = new ScmPurchasingCategoryFilterInput(); + filter.SearchCommon = new SearchCommonInputs(); + filter.SearchCommon.Limit = 20; + filter.Name = new StringFilterInput { Contains = query.Trim().Replace(" ", "%") }; + + var filter2 = new ScmPurchasingCategoryFilterInput(); + filter2.SearchCommon = new SearchCommonInputs(); + filter2.SearchCommon.Limit = 1; + filter2.Code = new StringFilterInput { Eq = query.Trim() }; + + + var result = await _aggieClient.ScmPurchasingCategorySearch.ExecuteAsync(filter); + var result2 = await _aggieClient.ScmPurchasingCategorySearch.ExecuteAsync(filter2); + + var data = result.ReadData(); + var data2 = result2.ReadData(); + + var temp1 = data.ScmPurchasingCategorySearch.Data.Select(a => new Commodity + { + Id = a.Code, + Name = a.Name, + IsActive = a.Enabled && DateTime.UtcNow.ToPacificTime().IsActiveDate(a.StartDateActive, a.EndDateActive) + }).ToArray(); + + var temp2 = data2.ScmPurchasingCategorySearch.Data.Select(a => new Commodity + { + Id = a.Code, + Name = a.Name, + IsActive = a.Enabled && DateTime.UtcNow.ToPacificTime().IsActiveDate(a.StartDateActive, a.EndDateActive) + }).ToArray(); + + return temp1.Where(a => a.IsActive).Union(temp2.Where(a => a.IsActive)).Distinct().ToArray(); + } /// /// Potentially we could cache this lookup, but it should really only be a SIT2 test thing.... diff --git a/Purchasing.Mvc/Controllers/AjaxController.cs b/Purchasing.Mvc/Controllers/AjaxController.cs index 0418d64d9..f37331362 100644 --- a/Purchasing.Mvc/Controllers/AjaxController.cs +++ b/Purchasing.Mvc/Controllers/AjaxController.cs @@ -17,10 +17,12 @@ namespace Purchasing.Mvc.Controllers public class AjaxController : ApplicationController { private readonly ISearchService _searchService; + private readonly IAggieEnterpriseService _aggieEnterpriseService; - public AjaxController(ISearchService searchService) + public AjaxController(ISearchService searchService, IAggieEnterpriseService aggieEnterpriseService) { _searchService = searchService; + _aggieEnterpriseService = aggieEnterpriseService; } /// @@ -41,9 +43,10 @@ public JsonNetResult SearchBuilding(string term) /// /// /// - public JsonResult SearchCommodityCodes(string searchTerm) + public JsonResult SearchCommodityCodes(string searchTerm) { - var results = _searchService.SearchCommodities(searchTerm).Select(a => new IdAndName(a.Id, a.Name)); + //var results = _searchService.SearchCommodities(searchTerm).Select(a => new IdAndName(a.Id, a.Name)); + var results = _aggieEnterpriseService.SearchCommodities(searchTerm).GetAwaiter().GetResult().Select(a => new IdAndName(a.Id, a.Name)).ToList(); return Json(results); }