From 6f0b0c1a3340fdbe34063c42f660de53b05b55e4 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Wed, 16 Jun 2021 14:43:14 +0200 Subject: [PATCH] Add tests for stemming and trimming Signed-off-by: Oliver Sand --- .../src/engines/LunrSearchEngine.test.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts index 969e579a53..f27d00097f 100644 --- a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts +++ b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts @@ -191,6 +191,72 @@ describe('LunrSearchEngine', () => { }); }); + it('should perform search query with trailing punctuation and return search results on match (trimming)', async () => { + const mockDocuments = [ + { + title: 'testTitle', + text: 'Hello World.', + location: 'test/location', + }, + ]; + + // Mock indexing of 1 document + testLunrSearchEngine.index('test-index', mockDocuments); + + // Perform search query + const mockedSearchResult = await testLunrSearchEngine.query({ + term: 'World', + filters: {}, + pageCursor: '', + }); + + // Should return 1 result as we are mocking the indexing of 1 document with match on the title field + expect(mockedSearchResult).toMatchObject({ + results: [ + { + document: { + title: 'testTitle', + text: 'Hello World.', + location: 'test/location', + }, + }, + ], + }); + }); + + it('should perform search query by similar words and return search results on match (stemming)', async () => { + const mockDocuments = [ + { + title: 'testTitle', + text: 'Searching', + location: 'test/location', + }, + ]; + + // Mock indexing of 1 document + testLunrSearchEngine.index('test-index', mockDocuments); + + // Perform search query + const mockedSearchResult = await testLunrSearchEngine.query({ + term: 'Search', + filters: {}, + pageCursor: '', + }); + + // Should return 1 result as we are mocking the indexing of 1 document with match on the title field + expect(mockedSearchResult).toMatchObject({ + results: [ + { + document: { + title: 'testTitle', + text: 'Searching', + location: 'test/location', + }, + }, + ], + }); + }); + it('should perform search query and return search results on match with filters', async () => { const mockDocuments = [ {