diff --git a/src/Marian/index.ts b/src/Marian/index.ts index 9a082ca..ee0f837 100644 --- a/src/Marian/index.ts +++ b/src/Marian/index.ts @@ -268,6 +268,7 @@ export default class Marian { } const res = await fetch(url); const toml = await res.text(); + return parse(toml); } catch (e) { log.error(`Error while fetching taxonomy: ${JSON.stringify(e)}`); diff --git a/src/Query/index.ts b/src/Query/index.ts index a7f1509..1f0d1e6 100644 --- a/src/Query/index.ts +++ b/src/Query/index.ts @@ -34,8 +34,8 @@ function constructBuryOperators(parts: Part[]): CompoundPart[] { //if given query matches a "part" result not in BURIED_PROPERTY(ex: Realm) docs, score remains unaffected { compound: { - must: [part], - mustNot: [ + must: [ + part, { text: { query: BURIED_PROPERTIES, @@ -43,13 +43,9 @@ function constructBuryOperators(parts: Part[]): CompoundPart[] { }, }, ], - }, - }, - //if given query matches a "part" result in BURIED_PROPERTY(ex: Realm) docs, bury that result - { - compound: { - must: [ - part, + // DOP-5772: Removed the part from the mustNot, and removed the second compound statement + // as that was interfering with the search results by surfacing pages we do not want. + mustNot: [ { text: { query: BURIED_PROPERTIES, @@ -57,6 +53,13 @@ function constructBuryOperators(parts: Part[]): CompoundPart[] { }, }, ], + }, + }, + //if given query matches a "part" result in BURIED_PROPERTY(ex: Realm) docs, bury that result + { + text: { + query: BURIED_PROPERTIES, + path: 'searchProperty', score: { boost: { value: BURIED_FACTOR } }, }, } @@ -121,15 +124,16 @@ export class Query { // if we need to boost for matching slug on an exact rawQuery match const boostedStrings = strippedMapping[this.rawQuery.trim()]; - if (Array.isArray(boostedStrings) && typeof boostedStrings[0] === 'string') { + + if (Array.isArray(boostedStrings)) { parts.push( ...boostedStrings.map((boostedString, i) => ({ text: { path: 'strippedSlug', query: [boostedString], - // Boost each entry slightly higher than the next so that entry - // order is respected in results - score: { boost: { value: 100 + 10 * (boostedStrings.length - i) } }, + // Use a constant score value to guarantee that we receive the order + // that we are expecting from the term-result-mappings object. + score: { constant: { value: 200 ** (boostedStrings.length - i) } }, }, })) ); diff --git a/src/Query/types.ts b/src/Query/types.ts index 0187b5d..84d11b3 100644 --- a/src/Query/types.ts +++ b/src/Query/types.ts @@ -8,7 +8,10 @@ type PathObj = { type Path = string | PathObj; export type Score = { - boost: { + boost?: { + value: number; + }; + constant?: { value: number; }; }; diff --git a/src/SearchPropertyMapping/index.ts b/src/SearchPropertyMapping/index.ts index fac5edb..380d48c 100644 --- a/src/SearchPropertyMapping/index.ts +++ b/src/SearchPropertyMapping/index.ts @@ -65,6 +65,7 @@ export const setPropertyMapping = async function () { const dbName = process.env['POOL_DB'] ?? 'pool_test'; const poolAtlasUri = verifyAndGetEnvVars(); + const client = await MongoClient.connect(poolAtlasUri); const db = client.db(dbName); const collection = db.collection(collectionName); diff --git a/src/data/term-result-mappings.ts b/src/data/term-result-mappings.ts index 58ee288..237f998 100644 --- a/src/data/term-result-mappings.ts +++ b/src/data/term-result-mappings.ts @@ -102,9 +102,9 @@ const resultMapping: ResultMapping = { 'reference/sql-aggregation-comparison', ], operator: ['reference/operator/query', 'reference/operator/update', 'reference/operator/aggregation-pipeline'], - exists: ['reference/operator/query/exists', 'atlas/atlas-search/exists', 'drivers/node/current/crud/query/query-document/'], - $exists: ['reference/operator/query/exists', 'atlas/atlas-search/exists', 'drivers/node/current/crud/query/query-document/'], - exist: ['reference/operator/query/exists', 'atlas/atlas-search/exists', 'drivers/node/current/crud/query/query-document/'], + exists: ['reference/operator/query/exists', 'atlas-search/exists', 'drivers/node/current/crud/query/query-document/'], + $exists: ['reference/operator/query/exists', 'atlas-search/exists', 'crud/query/query-document/'], + exist: ['reference/operator/query/exists', 'atlas-search/exists', 'drivers/node/current/crud/query/query-document/'], mongoclient: [ 'drivers/kotlin/coroutine/current/fundamentals/connection/mongoclientsettings', 'drivers/java/sync/current/connection/mongoclient', @@ -151,10 +151,7 @@ const resultMapping: ResultMapping = { $regex: ['reference/operator/query/regex', 'atlas/atlas-search/regex', 'reference/operator/aggregation/regexMatch'], $eq: ['reference/operator/query/eq', 'reference/operator/aggregation/eq', 'reference/operator/query/elemMatch'], $size: ['reference/operator/query/size', 'reference/operator/aggregation/size', 'tutorial/query-arrays'], - $sort: [ - 'reference/operator/update/sort', - 'reference/operator/aggregation/sort', - ], + $sort: ['reference/operator/update/sort', 'reference/operator/aggregation/sort'], $inc: [ 'reference/operator/update/inc', 'reference/method/db.collection.updateMany', @@ -178,10 +175,7 @@ const resultMapping: ResultMapping = { 'tutorial/update-documents-with-aggregation-pipeline', 'reference/operator/aggregation/sum', ], - $first: [ - 'reference/operator/aggregation/first', - 'reference/operator/aggregation/firstN', - ], + $first: ['reference/operator/aggregation/first', 'reference/operator/aggregation/firstN'], $count: ['reference/operator/aggregation/count', 'reference/command/count', 'atlas/atlas-search/counting'], indexes: ['indexes'], $addFields: [