-
Notifications
You must be signed in to change notification settings - Fork 17
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
Gestion des mots contractés #72
base: master
Are you sure you want to change the base?
Conversation
lib/communes.js
Outdated
|
||
const schema = { | ||
nom: { | ||
type: 'text', | ||
queryWith: 'nom', | ||
ref: 'code', | ||
replacePatern: abbreviations, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replacePatterns
@@ -1,4 +1,5 @@ | |||
const normalizeString = require('../normalizeString'); | |||
const replaceAbbreviations = require('../replaceAbbreviations'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le nom me parait trop spécifique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
À modifier
@@ -7,6 +8,7 @@ class TextIndex { | |||
if (!key) throw new Error('key is required'); | |||
this._key = key; | |||
this._boost = options.boost || {}; | |||
this._replacePatern = options.replacePatern || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_replacePatterns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas utile de mettre une valeur par défaut coûteuse à tester
@@ -31,6 +33,9 @@ class TextIndex { | |||
|
|||
find(terms, options = {}) { | |||
let boosted = false; | |||
|
|||
terms = replaceAbbreviations(terms, this._replacePatern); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this._replacePatterns) {
terms = replace(terms, this._replacePatterns);
}
const removeDiacritics = require('./removeDiacritics'); | ||
|
||
function replaceAbbreviations(search, abbreviations) { | ||
const terms = removeDiacritics(search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi utilise removeDiacritics
ici ?
function replaceAbbreviations(search, abbreviations) { | ||
const terms = removeDiacritics(search) | ||
.toLowerCase() | ||
.replace(/"/g, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un commentaire est bienvenu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que tu fais trop de chose dans cette fonction replace. Mieux faut avoir plusieurs fonctions, les appeler dans le bon ordre et leur donner le nom adapté.
const terms = removeDiacritics(search) | ||
.toLowerCase() | ||
.replace(/"/g, '') | ||
.replace(/-/g, ' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
.replace(/-/g, ' ') | ||
.split(' '); | ||
|
||
if (terms.length <= 1) return search; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
search est trop abstrait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Au lieu de faire toutes ces transformations pour rien, je ferai le test de la présence d'un espace dès le début.
On fait de l'auto-complétion, chaque miliseconde compte.
test/replaceAbbreviations.js
Outdated
const expect = require('expect.js'); | ||
const replaceAbbreviations = require('../lib/searchableCollection/replaceAbbreviations'); | ||
|
||
describe.only('replaceAbbreviations()', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only
test/replaceAbbreviations.js
Outdated
}); | ||
}); | ||
|
||
describe('Patern is contained in a word', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern
'st': 'saint', | ||
'ste': 'sainte', | ||
'cgne': 'campagne', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A rapprocher de la liste utilisée pour les noms de rues dans la BAN ?
https://github.com/etalab/ban-data/blob/master/data/abbrev.txt
@odtvince j'avais regardé mais très peu sont utiles dans les faits, et potentiellement trompeuses pour les communes. |
Gestion des mots contractés:
fix #61 Mots contractés