Add tests for stemming and trimming

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-06-16 14:43:14 +02:00
parent 53a883bd14
commit 6f0b0c1a33
@@ -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 = [
{