From 3ec487502e5a9bc286a0c18a987f02ed9931a9f1 Mon Sep 17 00:00:00 2001 From: Jesse Bye Date: Mon, 21 Jun 2021 09:32:19 -0700 Subject: [PATCH] Add test case; update changeset message Signed-off-by: Jesse Bye --- .changeset/short-numbers-carry.md | 2 +- .../src/engines/LunrSearchEngine.test.ts | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.changeset/short-numbers-carry.md b/.changeset/short-numbers-carry.md index be95300054..0b2fbe80ae 100644 --- a/.changeset/short-numbers-carry.md +++ b/.changeset/short-numbers-carry.md @@ -2,4 +2,4 @@ '@backstage/plugin-search-backend-node': patch --- -Escape : characters in the query +Fixed bug preventing searches with filter values containing `:` from returning results. diff --git a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts index b09777217a..22c775da8e 100644 --- a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts +++ b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts @@ -339,6 +339,46 @@ describe('LunrSearchEngine', () => { }); }); + it('should perform search query and return search results on match with filters that include a : character', async () => { + const mockDocuments = [ + { + title: 'testTitle', + text: 'testText', + location: 'test:location', + }, + { + title: 'testTitle', + text: 'testText', + location: 'test:location2', + }, + ]; + + // Mock indexing of 2 documents + testLunrSearchEngine.index('test-index', mockDocuments); + + // Perform search query + const mockedSearchResult = await testLunrSearchEngine.query({ + term: 'testTitle', + filters: { location: 'test:location2' }, + pageCursor: '', + }); + + // Should return 1 of 2 results as we are + // 1. Mocking the indexing of 2 documents + // 2. Matching on the location field with the filter { location: 'test:location2' } + expect(mockedSearchResult).toMatchObject({ + results: [ + { + document: { + title: 'testTitle', + text: 'testText', + location: 'test:location2', + }, + }, + ], + }); + }); + it('should perform search query and return search results on match, scoped to specific index', async () => { const mockDocuments = [ {