Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use user defined adresse #188

Merged
merged 4 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions api/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
22 changes: 11 additions & 11 deletions api/src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
});
});
50 changes: 26 additions & 24 deletions api/src/elastic/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }];
})
);

Expand Down Expand Up @@ -82,7 +82,7 @@ export const mapHit =
(
acc: any,
{
fields: { convention, idccs },
fields: { idccs },
}: { fields: { convention: string[]; idccs: string[] } }
) => {
idccs?.forEach((idcc) => {
Expand All @@ -92,7 +92,6 @@ export const mapHit =
const kaliData = conventionsSet[idccNum];
const o = {
idcc: idccNum,
// shortTitle: convention ? convention[0] : "",
...kaliData,
};
if (!acc.has(o.idcc)) {
Expand Down Expand Up @@ -124,49 +123,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,
};
Expand Down Expand Up @@ -303,10 +305,10 @@ export const entrepriseSearchBody = ({
!onlyDigits(query)
? {
multi_match: {
query,
type: "most_fields",
fields: ["naming", "namingMain"],
fuzziness: "AUTO",
query,
type: "most_fields",
},
}
: undefined,
Expand Down
10 changes: 5 additions & 5 deletions api/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -19,10 +19,10 @@ export const search = async ({
convention,
employer,
limit,
matchingLimit,
open,
query,
ranked,
matchingLimit,
});

// console.log(JSON.stringify(body, null, 2));
Expand All @@ -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));
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
47 changes: 21 additions & 26 deletions index/src/enterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,27 @@ 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,
codePostalEtablissement,
libelleCommuneEtablissement,
} = enterprise;

return [
complementAdresseEtablissement,
numeroVoieEtablissement,
indiceRepetitionEtablissement,
typeVoieEtablissement,
libelleVoieEtablissement,
codePostalEtablissement,
libelleCommuneEtablissement,
]
.filter((e) => e)
.join(" ");
};

export const mapEnterprise = (enterprise: Enterprise) => {
Expand Down