Skip to content

Commit

Permalink
fix(api): remove current item from relatedItems (#2000)
Browse files Browse the repository at this point in the history
fix #1874
  • Loading branch information
lionelB authored Dec 18, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ca89c69 commit eb34bb7
Showing 2 changed files with 20 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -605,23 +605,6 @@ Object {
},
"_type": "_doc",
"relatedItems": Array [
Object {
"breadcrumbs": Array [
Object {
"slug": "8-depart-de-lentreprise",
"title": "Départ de l'entreprise",
},
Object {
"slug": "81-demission",
"title": "Démission",
},
],
"description": "La démission permet au salarié, à son initiative, de rompre son contrat de travail, sous conditions.",
"slug": "demission-dun-salarie",
"source": "fiches_service_public",
"title": "Démission d'un salarié",
"url": "https://www.service-public.fr/particuliers/vosdroits/F2883",
},
Object {
"breadcrumbs": Array [
Object {
Original file line number Diff line number Diff line change
@@ -18,46 +18,35 @@ async function getRelatedItems({ queryVector, settings, slug }) {
SOURCES.LETTERS,
SOURCES.CONTRIBUTIONS
];
const {
body: {
responses: [esResponse, semResponse]

const requestBodies = [
{ index },
{
...getRelatedItemsBody({
settings,
sources
})
}
} = await elasticsearchClient.msearch({
body: [
{ index },
{
...getRelatedItemsBody({
settings,
sources
})
},
];
if (queryVector) {
requestBodies.push(
{ index },
// we +1 the size to remove the document source that should match perfectly for the given vector
{ ...getSemBody({ query_vector: queryVector, size: size + 1, sources }) }
]
});
);
}
const {
body: {
responses: [esResponse = [], semResponse = []]
}
} = await elasticsearchClient.msearch({ body: requestBodies });

const { hits: { hits: semanticHits } = { hits: [] } } = semResponse;
const { hits: { hits: fullTextHits } = { hits: [] } } = esResponse;

const filteredFullTextHits = fullTextHits.filter(
({ _source }) => !_source.slug.includes(slug)
);

if (!queryVector) {
return filteredFullTextHits
.slice(0, MAX_RESULTS)
.map(({ _source }) => _source);
}

const referenceId = settings[0].id;

return utils
.mergePipe(
semanticHits.filter(doc => doc._id !== referenceId),
filteredFullTextHits,
MAX_RESULTS
)
.mergePipe(semanticHits, fullTextHits, MAX_RESULTS)
.filter(({ _source }) => !_source.slug.includes(slug))
.map(({ _source }) => _source);
}

0 comments on commit eb34bb7

Please sign in to comment.