diff --git a/app/volunteering_db.ts b/app/volunteering_db.ts index 1d3db4b26234c9b1c23937cd8201a8d4e46b4848..359bdedb83329b2b91cc81634348fbfca244d73c 100644 --- a/app/volunteering_db.ts +++ b/app/volunteering_db.ts @@ -233,6 +233,15 @@ const MATCH_SKILL_CONFIDENCE_THRESHOLD = 0.8 const MAX_LIMIT = 100 const DEFAULT_LIMIT = 10 +const DEFAULT_RECO_TOPICS_V2 = [ + 'human-rights', + 'animal-welfare', + 'arts-culture', + 'literacy-education', + 'mental-physical-health', + 'democracy-politics', +] + const queryEmbeddingVector = (topics: string[], skills: string[]): number[] => { const queryVector: number[] = Array(EMBEDDING_DIMENSIONS).fill(0.0) for (const topic of topics) { @@ -532,16 +541,35 @@ export class PostgresVolunteeringDB implements VolunteeringDB { version, ) } else if (geolocationCoordinates) { - return this.queryRecosBasedOnLocation( + if (version === 'v2') { + return this.queryRecosBasedOnTopicsSkillsAndLocation( + offset, + limit, + DEFAULT_RECO_TOPICS_V2, + skills, + geolocationCoordinates, + version, + ) + } else { + return this.queryRecosBasedOnLocation( + offset, + limit, + geolocationCoordinates, + ) + } + } else if (topics.length > 0 || skills.length > 0) { + return this.queryRecosBasedOnTopicsAndSkills( offset, limit, - geolocationCoordinates, + topics, + skills, + version, ) - } else if (topics.length > 0 || skills.length > 0) { + } else if (version === 'v2') { return this.queryRecosBasedOnTopicsAndSkills( offset, limit, - topics, + DEFAULT_RECO_TOPICS_V2, skills, version, ) diff --git a/app/volunteering_db_test.ts b/app/volunteering_db_test.ts index 1ac76b931d2ecac5f1f2164c82736e6afecf5d2d..357c9d570bccf5f20dd6fbfbf54d85df6d0738d9 100644 --- a/app/volunteering_db_test.ts +++ b/app/volunteering_db_test.ts @@ -606,6 +606,36 @@ describe('VolunteeringDB', () => { }, ) }) + it('falls back to default topics if only a geolocation is given in V2', () => { + withMockedDependencies([dbFixtures.row1])( + async (volunteeringDB, _geoAPIClient) => { + const result = await volunteeringDB.engagementRecos('v2', { + limit: 10, + offset: 0, + topics: [], + skills: [], + geolocationId: 'mock-geolocation-id', + }) + assertEquals(result.totalResults, 1) + assertEquals(result.data.length, 1) + }, + ) + }) + it('falls back to default topics if no topics, skills or geolocation is given in V2', () => { + withMockedDependencies([dbFixtures.row1])( + async (volunteeringDB, _geoAPIClient) => { + const result = await volunteeringDB.engagementRecos('v2', { + limit: 10, + offset: 0, + topics: [], + skills: [], + geolocationId: 'mock-geolocation-id', + }) + assertEquals(result.totalResults, 1) + assertEquals(result.data.length, 1) + }, + ) + }) }) describe('filterEngagements', () => { diff --git a/smoketest/main.js b/smoketest/main.js index 99a6d49715aff26dcb61d3538f8f6bce37399100..1ecded4651c7297cea450f7ac589698bb38d4816 100644 --- a/smoketest/main.js +++ b/smoketest/main.js @@ -29,7 +29,7 @@ function forQuery(query, checkFunction) { export default () => { forQuery( `{ - engagementRecosV2(offset:0, limit:10, topics:["animal-welfare"]) { + engagementRecosV2(offset:0, limit:10) { data { engagement { id