From d60e09c230f96fbabc9b1fd0b8ac8612f54dce7c Mon Sep 17 00:00:00 2001 From: Joost Smit Date: Tue, 13 Aug 2024 22:06:57 +0200 Subject: [PATCH] test: added extra test cases --- src/lib/productSearchFilter.test.ts | 11 +++++++++++ src/lib/productSearchFilter.ts | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lib/productSearchFilter.test.ts b/src/lib/productSearchFilter.test.ts index a1b0c80..e11f7d2 100644 --- a/src/lib/productSearchFilter.test.ts +++ b/src/lib/productSearchFilter.test.ts @@ -16,9 +16,11 @@ describe("Product search filter", () => { }, name: { "nl-NL": "test", + "en-US": "my english test", }, slug: { "nl-NL": "test", + "en-US": "test", }, variants: [], searchKeywords: {}, @@ -226,6 +228,15 @@ describe("Product search filter", () => { caseInsensitive: false, } }).isMatch).toBeFalsy(); + + expect(match({ + wildcard: { + field: "name", + value: "*english Test*", + language: "en-US", + caseInsensitive: true, + } + }).isMatch).toBeTruthy(); }); test("by price range", async () => { diff --git a/src/lib/productSearchFilter.ts b/src/lib/productSearchFilter.ts index b25c149..7381490 100644 --- a/src/lib/productSearchFilter.ts +++ b/src/lib/productSearchFilter.ts @@ -98,9 +98,10 @@ export const parseSearchQuery = (searchQuery: _SearchQuery): ProductSearchFilter } if (isSearchFullTextExpression(searchQuery)) { - // TODO: Implement better fulltext search - // https://github.com/bevacqua/fuzzysearch - // With scoring (& therefore boosting): https://github.com/farzher/fuzzysort + // TODO: Implement better fulltext search, doesn't support all uses cases, see: https://docs.commercetools.com/api/search-query-language#fulltext + // Potential options to replace with: + // - https://github.com/bevacqua/fuzzysearch + // - With scoring (& therefore boosting): https://github.com/farzher/fuzzysort return generateFieldMatchFunc((value: any) => value.includes(searchQuery.fullText.value), searchQuery.fullText); } @@ -114,7 +115,7 @@ export const parseSearchQuery = (searchQuery: _SearchQuery): ProductSearchFilter } if (isSearchWildCardExpression(searchQuery)) { - // TODO: Implement better wildcard search + // TODO: Implement better (actual) wildcard search const generateWildcardMatchFunc = (value: any) => { const wildCardValues = searchQuery.wildcard.value.split("*").filter((v: string) => !!v);