mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
* adding similarity check * adding paging * fixing tests * docu * better error handling * fixing tests * adjusting page limit * fixing login screen * cleanup * upgrade browser list * prevent spamming the log * fixing tests * removing job listings when removing a job or the user
37 lines
877 B
JavaScript
37 lines
877 B
JavaScript
const stringSimilarity = require('string-similarity');
|
|
|
|
//if the score is higher than this, it will be considered a match
|
|
const MAX_DICE_INDEX = 0.7;
|
|
|
|
/**
|
|
* The similarity check is based on the dice coefficient. => https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
|
|
*
|
|
* @type {module.SimilarityCacheEntry}
|
|
*/
|
|
module.exports = class SimilarityCacheEntry {
|
|
constructor(time) {
|
|
this.time = time;
|
|
this.values = [];
|
|
}
|
|
|
|
setCacheEntry = (entry) => {
|
|
this.values.push(entry);
|
|
};
|
|
|
|
getTime = () => {
|
|
return this.time;
|
|
};
|
|
|
|
hasSimilarEntries = (value) => {
|
|
if (this.values.length > 0) {
|
|
for (let i = 0; i < this.values.length; i++) {
|
|
const index = stringSimilarity.compareTwoStrings(value, this.values[i]);
|
|
if (index >= MAX_DICE_INDEX) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
};
|