Skip to content

Commit

Permalink
Merge pull request #1 from betagouv/fix_duplicate_results
Browse files Browse the repository at this point in the history
Remove duplicates from search results
  • Loading branch information
jillro authored Sep 12, 2024
2 parents b785bc2 + c188710 commit 00eb51c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/app/rechercher/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ async function getSpecialites(specialitesId: string[], substancesId: string[]) {
)
.where("Specialite.SpecId", "in", liste_CIS_MVP)
.selectAll("Specialite")
.select("NomId")
.select(({ fn }) => [
fn<Array<string>>("json_arrayagg", ["NomId"]).as("SubsNomId"),
])
.groupBy("Specialite.SpecId")
.execute()
: [];
}
Expand Down Expand Up @@ -105,7 +108,8 @@ async function getResults(query: string): Promise<SearchResultItem[]> {
specialiteGroups
.filter(([, specialites]) =>
specialites.find(
(s) => s.NomId && s.NomId.trim() === substance.NomId.trim(),
(s) =>
s.SubsNomId && s.SubsNomId.includes(substance.NomId.trim()),
),
)
.forEach(([groupName, specialites]) => {
Expand Down Expand Up @@ -133,7 +137,8 @@ async function getResults(query: string): Promise<SearchResultItem[]> {
if (
specialiteGroup &&
!acc.find(
(a) => "groupName" in a && a.groupName === specialiteGroup[0],
({ item }) =>
"groupName" in item && item.groupName === specialiteGroup[0],
)
) {
const [groupName, specialites] = specialiteGroup;
Expand Down

0 comments on commit 00eb51c

Please sign in to comment.