From 5c0a198fea9c9bbd44a8a2833718eec1a144118e Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Thu, 26 May 2022 00:20:59 +0200 Subject: [PATCH 1/4] chore: lint --- api/.eslintrc | 15 ++++++----- api/src/__tests__/api.test.ts | 22 ++++++++-------- api/src/elastic/queries.ts | 49 +++++++++++++++++++---------------- api/src/lib/index.ts | 10 +++---- api/src/routes/index.ts | 2 +- 5 files changed, 51 insertions(+), 47 deletions(-) diff --git a/api/.eslintrc b/api/.eslintrc index ad0ec147..33eb0563 100644 --- a/api/.eslintrc +++ b/api/.eslintrc @@ -2,13 +2,14 @@ "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2020, - "sourceType": "module", + "sourceType": "module" }, + "ignorePatterns": ["__tests__"], "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - "@socialgouv/eslint-config-recommended", - "plugin:import/typescript" + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + "@socialgouv/eslint-config-recommended", + "plugin:import/typescript" ] -} \ No newline at end of file +} diff --git a/api/src/__tests__/api.test.ts b/api/src/__tests__/api.test.ts index 1381c88c..b6a8921c 100644 --- a/api/src/__tests__/api.test.ts +++ b/api/src/__tests__/api.test.ts @@ -2,8 +2,8 @@ import * as http from "http"; import Koa from "koa"; import supertest from "supertest"; -import { API_PREFIX, router } from "../routes"; import { ELASTICSEARCH_INDEX_NAME } from "../elastic"; +import { API_PREFIX, router } from "../routes"; const app = new Koa(); app.use(router.routes()); @@ -195,10 +195,10 @@ describe("Test entreprise search", () => { describe("Test api params", () => { test("not only open", async () => { const { body: b1 } = await searchCall({ + convention: false, + limit: 1, open: "false", query: "michelin", - limit: 1, - convention: false, }); expect( b1.entreprises[0].firstMatchingEtablissement @@ -214,29 +214,29 @@ describe("Test api params", () => { const { body: notOnlyEmployer } = await searchCall({ employer: false, - query: "michelin", limit: 50, + query: "michelin", }); expect(getNotEmployer(notOnlyEmployer).length).toBeGreaterThan(0); const { body: onlyEmployer } = await searchCall({ employer: true, - query: "michelin", limit: 50, + query: "michelin", }); expect(getNotEmployer(onlyEmployer).length).toBe(0); }); test("not with convention", async () => { const { body: withConvention } = await searchCall({ - query: "truc", limit: 1, + query: "truc", }); const { body: noConvention } = await searchCall({ convention: false, - query: "truc", limit: 1, + query: "truc", }); expect(noConvention.entreprises[0].conventions).toEqual([]); expect(withConvention.entreprises[0].conventions.length).toBeGreaterThan(0); @@ -259,20 +259,20 @@ describe("Test api params", () => { expect(unranked[2].label).toEqual("MICHELIN EDITIONS"); }); - test("test with or without etablissements", async () => { + test("with or without etablissements", async () => { const { body: { entreprises }, - } = await searchCall({ query: "michelin", matchingLimit: 0 }); + } = await searchCall({ matchingLimit: 0, query: "michelin" }); expect(entreprises[0].allMatchingEtablissements.length).toBe(0); const { body: { entreprises: resp2 }, - } = await searchCall({ query: "michelin", matchingLimit: 5 }); + } = await searchCall({ matchingLimit: 5, query: "michelin" }); expect(resp2[0].allMatchingEtablissements.length).toBe(5); const { body: { entreprises: resp3 }, - } = await searchCall({ query: "carrefour", matchingLimit: -1 }); + } = await searchCall({ matchingLimit: -1, query: "carrefour" }); expect(resp3[0].allMatchingEtablissements.length).toBe(194); }); }); diff --git a/api/src/elastic/queries.ts b/api/src/elastic/queries.ts index bef32e6d..7c0c9169 100644 --- a/api/src/elastic/queries.ts +++ b/api/src/elastic/queries.ts @@ -8,7 +8,7 @@ const defaultLimit = 20; const conventionsSet = Object.fromEntries( kaliConventions.map((c) => { const { num, etat, id, mtime, texte_de_base, url, title, shortTitle } = c; - return [num, { etat, id, mtime, texte_de_base, title, url, shortTitle }]; + return [num, { etat, id, mtime, shortTitle, texte_de_base, title, url }]; }) ); @@ -82,7 +82,7 @@ export const mapHit = ( acc: any, { - fields: { convention, idccs }, + fields: { idccs }, }: { fields: { convention: string[]; idccs: string[] } } ) => { idccs?.forEach((idcc) => { @@ -124,49 +124,52 @@ export const mapHit = etablissementSiege, }, }: any) => ({ - address: address && address[0], - siret: siret && siret[0], - idccs, activitePrincipaleEtablissement: getFirstIfSet( activitePrincipaleEtablissement ), - etablissementSiege: getFirstIfSet(etablissementSiege), //|| false, + address: address && address[0], + //|| false, codeCommuneEtablissement: getFirstIfSet(codeCommuneEtablissement), + + codePaysEtrangerEtablissement, + codePostalEtablissement, + etablissementSiege: getFirstIfSet(etablissementSiege), + idccs, libelleCommuneEtablissement, - codePaysEtrangerEtablissement, + siret: siret && siret[0], }) ); return { activitePrincipale, activitePrincipaleUniteLegale, + allMatchingEtablissements, + caractereEmployeurUniteLegale, categorieJuridiqueUniteLegale, + conventions: Array.from(conventions.values()), + dateCessation: + etatAdministratifUniteLegale === "C" ? dateDebut : undefined, dateCreationUniteLegale, dateDebut, - caractereEmployeurUniteLegale, - conventions: Array.from(conventions.values()), etablissements: parseInt(etablissements), etatAdministratifUniteLegale, - dateCessation: - etatAdministratifUniteLegale === "C" ? dateDebut : undefined, - highlightLabel, - label, - matching, firstMatchingEtablissement: { + activitePrincipaleEtablissement, address: geo_adresse, + categorieEntreprise, codeCommuneEtablissement, - codePostalEtablissement, - libelleCommuneEtablissement, codePaysEtrangerEtablissement, + codePostalEtablissement, + etablissementSiege, + etatAdministratifEtablissement, idccs, - categorieEntreprise, + libelleCommuneEtablissement, siret, - etatAdministratifEtablissement, - etablissementSiege, - activitePrincipaleEtablissement, }, - allMatchingEtablissements, + highlightLabel, + label, + matching, simpleLabel, siren, }; @@ -303,10 +306,10 @@ export const entrepriseSearchBody = ({ !onlyDigits(query) ? { multi_match: { - query, - type: "most_fields", fields: ["naming", "namingMain"], fuzziness: "AUTO", + query, + type: "most_fields", }, } : undefined, diff --git a/api/src/lib/index.ts b/api/src/lib/index.ts index 4a1684ac..bd78a131 100644 --- a/api/src/lib/index.ts +++ b/api/src/lib/index.ts @@ -1,4 +1,4 @@ -import { elasticsearchClient, ELASTICSEARCH_INDEX_NAME } from "../elastic"; +import { ELASTICSEARCH_INDEX_NAME, elasticsearchClient } from "../elastic"; import type { SearchArgs } from "../elastic/queries"; import { entrepriseSearchBody, mapHit } from "../elastic/queries"; @@ -19,10 +19,10 @@ export const search = async ({ convention, employer, limit, + matchingLimit, open, query, ranked, - matchingLimit, }); // console.log(JSON.stringify(body, null, 2)); @@ -46,14 +46,14 @@ export const searchEntreprise = async ( ) => { const body = entrepriseSearchBody({ addAllConventions: true, + boostSiege: true, convention: false, employer: false, limit: 1, + matchingLimit, open: false, query: siren, ranked: false, - matchingLimit, - boostSiege: true, }); // console.log(JSON.stringify(body, null, 2)); @@ -78,10 +78,10 @@ export const searchEtablissement = async (siret: string) => { convention: false, employer: false, limit: 1, + matchingLimit: 1, open: false, query: siret, ranked: false, - matchingLimit: 1, }); const response = await elasticsearchClient.search({ diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index 3db2917b..e0d9c9e9 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -39,9 +39,9 @@ router.get(`${API_PREFIX}/search`, async (ctx) => { convention: parseBoolean(convention as string, false), employer: parseBoolean(employer as string, false), limit: parseInt(limit as string), + matchingLimit: parseInteger(matchingLimit as string, 20), open: parseBoolean(open as string, true), query: query as string, - matchingLimit: parseInteger(matchingLimit as string, 20), ranked: parseBoolean(ranked as string, true), }); ctx.body = { entreprises }; From 4cb26708cc191b60aa2c50b33196bddf450e1bee Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Thu, 26 May 2022 00:58:35 +0200 Subject: [PATCH 2/4] fix(index): dont use geo_adresse field --- api/src/elastic/queries.ts | 2 +- index/src/enterprise.ts | 43 +++++++++++++++----------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/api/src/elastic/queries.ts b/api/src/elastic/queries.ts index 7c0c9169..de545760 100644 --- a/api/src/elastic/queries.ts +++ b/api/src/elastic/queries.ts @@ -53,6 +53,7 @@ export const mapHit = activitePrincipale, etablissements, siret, + complementAdresseEtablissement, geo_adresse, naming, namingMain, @@ -92,7 +93,6 @@ export const mapHit = const kaliData = conventionsSet[idccNum]; const o = { idcc: idccNum, - // shortTitle: convention ? convention[0] : "", ...kaliData, }; if (!acc.has(o.idcc)) { diff --git a/index/src/enterprise.ts b/index/src/enterprise.ts index ab5a1c77..e2ecb7a0 100644 --- a/index/src/enterprise.ts +++ b/index/src/enterprise.ts @@ -156,32 +156,23 @@ export const mappings = { }; const buildAddress = (enterprise: Enterprise) => { - if (enterprise.geo_adresse) { - // the second option is upper case, so we make it uppercase too - return enterprise.geo_adresse.toUpperCase(); - } else { - const { - complementAdresseEtablissement, - numeroVoieEtablissement, - indiceRepetitionEtablissement, - typeVoieEtablissement, - libelleVoieEtablissement, - codePostalEtablissement, - libelleCommuneEtablissement, - } = enterprise; - - return [ - complementAdresseEtablissement, - numeroVoieEtablissement, - indiceRepetitionEtablissement, - typeVoieEtablissement, - libelleVoieEtablissement, - codePostalEtablissement, - libelleCommuneEtablissement, - ] - .filter((e) => e) - .join(" "); - } + const { + complementAdresseEtablissement, + numeroVoieEtablissement, + indiceRepetitionEtablissement, + typeVoieEtablissement, + libelleVoieEtablissement, + } = enterprise; + + return [ + complementAdresseEtablissement, + numeroVoieEtablissement, + indiceRepetitionEtablissement, + typeVoieEtablissement, + libelleVoieEtablissement, + ] + .filter((e) => e) + .join(" "); }; export const mapEnterprise = (enterprise: Enterprise) => { From a75cf9654211e198aa394a1c3221d7695266cdfb Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Thu, 26 May 2022 02:14:37 +0200 Subject: [PATCH 3/4] fix(adresse): include cp+ville --- index/src/enterprise.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index/src/enterprise.ts b/index/src/enterprise.ts index e2ecb7a0..ff435d16 100644 --- a/index/src/enterprise.ts +++ b/index/src/enterprise.ts @@ -162,6 +162,8 @@ const buildAddress = (enterprise: Enterprise) => { indiceRepetitionEtablissement, typeVoieEtablissement, libelleVoieEtablissement, + codePostalEtablissement, + libelleCommuneEtablissement, } = enterprise; return [ @@ -170,6 +172,8 @@ const buildAddress = (enterprise: Enterprise) => { indiceRepetitionEtablissement, typeVoieEtablissement, libelleVoieEtablissement, + codePostalEtablissement, + libelleCommuneEtablissement, ] .filter((e) => e) .join(" "); From 7b47a9da1a3412258ec6b7b8ce839f857413bea4 Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Thu, 2 Jun 2022 11:32:15 +0200 Subject: [PATCH 4/4] chore: lint --- api/src/elastic/queries.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/elastic/queries.ts b/api/src/elastic/queries.ts index de545760..18b3b3bc 100644 --- a/api/src/elastic/queries.ts +++ b/api/src/elastic/queries.ts @@ -53,7 +53,6 @@ export const mapHit = activitePrincipale, etablissements, siret, - complementAdresseEtablissement, geo_adresse, naming, namingMain,