Test rank handling in all search engines.

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2022-06-09 17:26:28 +02:00
parent f7f5a6c6a3
commit c7ce7b1eb0
4 changed files with 37 additions and 4 deletions
@@ -523,6 +523,7 @@ describe('ElasticSearchSearchEngine', () => {
.map((_, i) => ({
type: 'mytype',
document: { value: `${i}` },
rank: i + 1,
})),
),
});
@@ -567,6 +568,7 @@ describe('ElasticSearchSearchEngine', () => {
.map((_, i) => ({
type: 'mytype',
document: { value: `${i}` },
rank: i + 1,
})),
),
nextPageCursor: 'MQ==',
@@ -614,6 +616,7 @@ describe('ElasticSearchSearchEngine', () => {
.map((_, i) => ({
type: 'mytype',
document: { value: `${i}` },
rank: i + 1,
}))
.slice(25),
),
@@ -667,6 +670,7 @@ describe('ElasticSearchSearchEngine', () => {
.map((_, i) => ({
type: 'mytype',
document: { value: `${i}` },
rank: i + 1,
highlight: {
preTag: '<tag>',
postTag: '</tag>',
@@ -174,6 +174,7 @@ describe('PgSearchEngine', () => {
location: 'location-1',
},
type: 'my-type',
rank: 1,
},
],
nextPageCursor: undefined,
@@ -215,6 +216,7 @@ describe('PgSearchEngine', () => {
location: `location-${i}`,
},
type: 'my-type',
rank: i + 1,
})),
nextPageCursor: 'MQ==',
});
@@ -257,6 +259,7 @@ describe('PgSearchEngine', () => {
location: `location-${i}`,
},
type: 'my-type',
rank: i + 1,
}))
.slice(25),
previousPageCursor: 'MA==',
@@ -431,6 +431,7 @@ describe('LunrSearchEngine', () => {
location: 'test/location',
},
type: 'test-index',
rank: 1,
},
],
nextPageCursor: undefined,
@@ -469,6 +470,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
location: 'test/location',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -521,6 +523,7 @@ describe('LunrSearchEngine', () => {
location: `${highlightTags.pre}test/location${highlightTags.post}`,
},
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -559,6 +562,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
location: 'test/location',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -598,6 +602,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
location: 'test/location',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -637,6 +642,7 @@ describe('LunrSearchEngine', () => {
text: 'Hello World.',
location: 'test/location',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -676,6 +682,7 @@ describe('LunrSearchEngine', () => {
text: 'Searching',
location: 'test/location',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -722,6 +729,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
location: 'test/location2',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -777,6 +785,7 @@ describe('LunrSearchEngine', () => {
location: 'test/location2',
extraField: 'testExtraField',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -823,6 +832,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
location: 'test:location2',
},
rank: 1,
},
],
nextPageCursor: undefined,
@@ -886,6 +896,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
title: 'testTitle',
},
rank: 1,
},
{
document: {
@@ -893,6 +904,7 @@ describe('LunrSearchEngine', () => {
text: 'testText',
title: 'testTitle',
},
rank: 2,
},
],
nextPageCursor: undefined,
@@ -931,6 +943,7 @@ describe('LunrSearchEngine', () => {
location: `test/location/${i}`,
},
type: 'test-index',
rank: i + 1,
})),
nextPageCursor: 'MQ==',
previousPageCursor: undefined,
@@ -968,6 +981,7 @@ describe('LunrSearchEngine', () => {
location: `test/location/${i}`,
},
type: 'test-index',
rank: i + 1,
}))
.slice(25),
nextPageCursor: undefined,
@@ -44,6 +44,7 @@ describe('AuthorizedSearchEngine', () => {
.fill(0)
.map((_, index) => ({
type,
rank: index + 1,
document: {
title: `${type}_doc_${index}`,
authorization: withAuthorization
@@ -261,9 +262,11 @@ describe('AuthorizedSearchEngine', () => {
}),
);
const expectedResult = { ...usersWithAuth[8], rank: 1 };
await expect(
authorizedSearchEngine.query({ term: '' }, options),
).resolves.toEqual({ results: [usersWithAuth[8]] });
).resolves.toEqual({ results: [expectedResult] });
expect(mockedQuery).toHaveBeenCalledWith(
{ term: '', types: ['users'] },
@@ -275,6 +278,7 @@ describe('AuthorizedSearchEngine', () => {
const searchResults = [
{
type: 'templates',
rank: 1,
document: {
title: `doc_0_a`,
authorization: { resourceRef: `template_doc_0` },
@@ -282,6 +286,7 @@ describe('AuthorizedSearchEngine', () => {
},
{
type: 'templates',
rank: 2,
document: {
title: `doc_0_b`,
authorization: { resourceRef: `template_doc_0` },
@@ -419,7 +424,9 @@ describe('AuthorizedSearchEngine', () => {
{ token: 'token' },
);
const expectedResult = allDocuments.slice(0, 25);
const expectedResult = allDocuments
.slice(0, 25)
.map((r, i) => ({ ...r, rank: i + 1 }));
const expectedFirstRequestCursor = 'MQ==';
expect(result).toEqual({
@@ -510,7 +517,8 @@ describe('AuthorizedSearchEngine', () => {
const expectedResult = allDocuments
.filter(d => d.type !== typeServices)
.slice(0, 25);
.slice(0, 25)
.map((d, i) => ({ ...d, rank: i + 1 }));
const expectedFirstRequestCursor = 'MQ==';
expect(result).toEqual({
@@ -587,8 +595,12 @@ describe('AuthorizedSearchEngine', () => {
{ token: 'token' },
);
const expectedResults = servicesWithAuth
.slice(5)
.map((r, i) => ({ ...r, rank: 25 + i + 1 }));
expect(result).toEqual({
results: servicesWithAuth.slice(5),
results: expectedResults,
previousPageCursor: encodePageCursor({ page: 0 }),
});
});