Skip to content

Commit

Permalink
Boost ranking for people with multiple names (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle authored Jul 3, 2024
1 parent 88d87ea commit 035fb59
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/utils/ldap.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ function score (a, q) {
term = term.toLowerCase();
for (const attr of attributes) {
const name = util.removeAccents(a[attr]).toLowerCase();
const subnames = name.split(/\s+/);
if (name === term && attr === 'name') {
points += 4;
points += 100;
} else if (name === term && attr === 'firstname') {
points += 3;
points += 99;
} else if (subnames.includes(term)) {
points += 49;
} else if (name.startsWith(term) && attr === 'name') {
points += 2;
} else if (name.startsWith(term) && attr === 'firstname') {
Expand Down
9 changes: 8 additions & 1 deletion tests/people.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Test API People ("/api/ldap")', () => {
mysql.createPool().getConnection.mockResolvedValue(mockConnection);

const mockApimdResponsePersons = require(
'./resources/apimd/persons-670001-670006.json'
'./resources/apimd/persons.json'
);
const mockApimdResponseRooms = require(
'./resources/apimd/rooms-cloud-city.json'
Expand Down Expand Up @@ -224,6 +224,13 @@ describe('Test API People ("/api/ldap")', () => {
expect(JSON.parse(response.text)).toStrictEqual(jsonResult);
});

test('It should find Lor San Tekka', async () => {
const jsonResult = require('./resources/people/json-name-san.json');
const response = await request(app).get('/api/ldap?q=San');
expect(response.statusCode).toBe(200);
expect(JSON.parse(response.text)).toStrictEqual(jsonResult);
});

test('It should find Bo Katan Kryze', async () => {
const jsonResult = require('./resources/people/json-name-kryze-fr.json');
const response = await request(app).get('/api/ldap?q=Bo Katan Kryze');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@
}
]
},
{
"id": "670007",
"rooms": [
{
"unitid": "11501",
"name": "Jakku 316",
"hidden": 0
}
],
"phones": [
{
"unitid": "11501",
"number": "+41211234567",
"hidden": 0
}
]
},
{
"id": "999999",
"rooms": [
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/cadidb/getUnit-nevarro.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"libelle": "Nevarro est une planète volcanique située dans les territoires de la bordure extérieure de la galaxie.",
"libelle_en": "",
"hierarchie": "EPFL SO TV-3 NEVARRO",
"resp_sciper": "670007",
"resp_sciper": "670097",
"resp_nom": "Karga",
"resp_nom_usuel": null,
"resp_prenom": "Greef",
Expand Down
4 changes: 4 additions & 0 deletions tests/resources/cadidb/getUnits.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
{
"sigle": "KALEVALA",
"id_unite": 11401
},
{
"sigle": "JAKKU",
"id_unite": 11501
}
]
25 changes: 25 additions & 0 deletions tests/resources/ldap/directory.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,30 @@
"postOfficeBox": "Station Kryze",
"postalAddress": "EPFL SO TV-4 KALEVALA $ Base Kryze (Bâtiment Kalevala) $ Station Kryze $ Castle Kryze"
}
},
{
"dn": "cn=Lor San Tekka,ou=jakku,ou=ep-7,ou=se,o=epfl,c=ch",
"attributes": {
"cn": ["Lor San Tekka", "San Tekka"],
"sn": "San Tekka",
"givenName": "Lor",
"displayName": "Lor San Tekka",
"uniqueIdentifier": "670007",
"mail": "[email protected]",
"objectClass": "Person",
"roomNumber": "Jakku 316",
"telephoneNumber": "+41 21 1234567",
"EPFLAccredOrder": "1",
"description": "Explorateur",
"description;lang-en": "Explorer",
"ou": [
"JAKKU",
"Jakku était une planète désertique isolée située dans le système Jakku, dans les confins occidentaux de la bordure intérieure de la galaxie."
],
"ou;lang-en": "Jakku was a remote desert planet located in the Jakku system, within the Western Reaches of the galaxy's Inner Rim.",
"postalCode": "JA-1468",
"postOfficeBox": "Station 316",
"postalAddress": "EPFL SE EP-7 JAKKU $ Jakku 316 $ Station 316 $ JA-316"
}
}
]
23 changes: 23 additions & 0 deletions tests/resources/people/json-name-san.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"sciper": "670007",
"rank": 0,
"name": "San Tekka",
"firstname": "Lor",
"email": "[email protected]",
"accreds": [
{
"phoneList": ["+41211234567"],
"officeList": ["Jakku 316"],
"path": "EPFL/SE/EP-7/JAKKU",
"acronym": "JAKKU",
"order": 1,
"position": "Explorateur",
"name": "Jakku était une planète désertique isolée située dans le système Jakku, dans les confins occidentaux de la bordure intérieure de la galaxie.",
"rank": 0,
"code": 11501
}
],
"profile": "lor.san.tekka"
}
]
2 changes: 1 addition & 1 deletion tests/resources/unit/unit-nevarro-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"CH-1015 Lausanne"
],
"head": {
"sciper": "670007",
"sciper": "670097",
"name": "Karga",
"firstname": "Greef"
}
Expand Down

0 comments on commit 035fb59

Please sign in to comment.