feat(shaarli/edit) accurate tag matching
This commit is contained in:
parent
5414a36b2d
commit
f919986d50
@ -317,18 +317,28 @@
|
||||
|
||||
var descriptionEl = document.getElementById("lf_description{$batchId}");
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
function updateSuggestionList() {
|
||||
var desc = descriptionEl.value.toLowerCase();
|
||||
// Supprime les liens archive pour ne pas matcher "archive.org" ou similaires
|
||||
var rawDesc = descriptionEl.value.replace(/https?:\/\/web\.archive\.org\S*/gi, '').replace(/Archive:/gi, '');
|
||||
var desc = rawDesc.toLowerCase();
|
||||
var existing = tagify.value.map(function(item){ return item.value; });
|
||||
matchCounts = {};
|
||||
var suggested = {};
|
||||
|
||||
// Calcule le nombre d’occurrences de chaque tag via les règles
|
||||
mapping.forEach(function(entry) {
|
||||
var matchesKey = entry.keys.filter(function(k){ return desc.includes(k.toLowerCase()); }).length;
|
||||
entry.tags.forEach(function(t) {
|
||||
matchCounts[t] = (matchCounts[t] || 0) + matchesKey;
|
||||
suggested[t] = (suggested[t] || 0) + (matchesKey > 0 ? 1 : 0);
|
||||
entry.keys.forEach(function(key) {
|
||||
// crée un motif regex pour mot entier (ou pluriel)
|
||||
var pattern = new RegExp('\\b' + escapeRegExp(key.toLowerCase()) + '(?:s)?\\b', 'i');
|
||||
if (pattern.test(desc)) {
|
||||
entry.tags.forEach(function(t) {
|
||||
matchCounts[t] = (matchCounts[t] || 0) + 1;
|
||||
suggested[t] = (suggested[t] || 0) + 1;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -344,7 +354,7 @@
|
||||
lowPriority = lowPriority.slice(0, 5);
|
||||
var ordered = highPriority.concat(medPriority).concat(lowPriority);
|
||||
|
||||
// On complète la whitelist avec le reste des tags non déjà listés
|
||||
// Complète la whitelist avec le reste des tags non déjà listés
|
||||
var fallback = allTags.filter(function(t) {
|
||||
return ordered.indexOf(t) === -1 && existing.indexOf(t) === -1;
|
||||
});
|
||||
@ -389,4 +399,4 @@
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
{/if}
|
||||
{/if}
|
||||
|
Loading…
x
Reference in New Issue
Block a user