openvibers/openvibe.tours Commits

Search documents' bodies hold only what their summary does not (#42)

OP OpenVibers committed 11 days ago · 89a9d2b7b5 · 2 files, +5 −4

Search's snippet reads the summary and the body together, and a place's body began with its
title and the summary's first sentence, so results read "Attraction in Chongqing… Attraction in
Chongqing". A place's body is now its long description (past the summary's 220 characters) and
its address; a city's its region line, its long summary and the things-to-do line; a walk's its
long summary.

Changes

ddiff --git a/server/search-index.js b/server/search-index.js
iindex e414e2e..f0f3f97 100644
---- a/server/search-index.js
++++ b/server/search-index.js
@@@ -34,7 +34,8 @@ function describePlace(row) {
listed: true,
title,
summary: [about, clip(row.description, 220), ...facts].filter(Boolean).join(' '),
-- body: [title, about, row.description, row.address, ...facts].filter(Boolean).join('\n'),
++ // The body holds only what the summary does not (Search's snippet reads both, and repeated the first line).
++ body: [row.description && row.description.length > 220 ? row.description : '', row.address].filter(Boolean).join('\n'),
facets: { city: row.city_slug, country: row.country, kind: row.kind },
authorship: { mode: 'imported' },
publishedAt: iso(row.created_at),
@@@ -51,7 +52,7 @@ function describeCity(row) {
noindex: !places && !routes,
title: `${row.name}, ${row.country}`,
summary: [clip(row.summary, 260), what].filter(Boolean).join(' '),
-- body: [`${row.name}, ${row.region ? `${row.region}, ` : ''}${row.country}`, row.summary, what, 'Things to do, places to see, walks, stays and flights.'].filter(Boolean).join('\n'),
++ body: [row.region ? `${row.name}, ${row.region}, ${row.country}` : '', row.summary && row.summary.length > 260 ? row.summary : '', 'Things to do, places to see, walks, stays and flights.'].filter(Boolean).join('\n'),
facets: { city: row.id, country: row.country, places, routes },
authorship: { mode: 'imported' },
publishedAt: iso(row.created_at),
@@@ -68,7 +69,7 @@ function describeRoute(row) {
noindex: !Number(row.stop_count),
title: row.title,
summary: [about, clip(row.summary, 220)].filter(Boolean).join(' '),
-- body: [row.title, about, row.summary].filter(Boolean).join('\n'),
++ body: row.summary && row.summary.length > 220 ? row.summary : '',
facets: { city: row.city_slug, country: row.country, stops: Number(row.stop_count) || 0, distance_m: Number(row.distance_m) || 0, duration_min: Number(row.duration_min) || 0 },
authorship: { mode: 'imported' },
publishedAt: iso(row.created_at),
ddiff --git a/test/place-names.test.js b/test/place-names.test.js
iindex b4705e5..292021f 100644
---- a/test/place-names.test.js
++++ b/test/place-names.test.js
@@@ -49,7 +49,7 @@ const node = (tags) => ({ type: 'node', id: 9001, lat: 29.56, lon: 106.58, tags:
const env = (await t.ctx.s.db.many("SELECT envelope FROM event_outbox WHERE envelope->'payload'->>'id' = $1", [id])).pop();
assert.ok(env, 'an envelope for the place');
assert.strictEqual(env.envelope.payload.title, 'Hongya Cave (洪崖洞)');
-- assert.match(env.envelope.payload.body, /Hongya Cave \(洪崖洞\)/);
++ assert.ok(!String(env.envelope.payload.body || '').includes('Attraction in'), 'the body does not repeat the summary (the snippet reads both)');
});
await check('the places job names a version, so a run under older rules is not fresh', async () => {