fix: assuntos sem duplicatas em inglês no cartão e no filtro

This commit is contained in:
2026-09-30 19:04:19 +02:00
parent 9e7a885bdd
commit aedef870c1
+18 -9
View File
@@ -1277,11 +1277,7 @@ function showCard(data) {
// this piece's dc.subject, one chip each (accent/case duplicates folded) // this piece's dc.subject, one chip each (accent/case duplicates folded)
const tagsEl = document.getElementById('card-tags'); const tagsEl = document.getElementById('card-tags');
tagsEl.replaceChildren(); tagsEl.replaceChildren();
const seen = new Set(); subjectsOf(meta).forEach(t => {
[].concat(meta.subject || []).forEach(t => {
const k = deburr(String(t)).trim();
if (!k || seen.has(k)) return;
seen.add(k);
const chip = document.createElement('span'); const chip = document.createElement('span');
chip.textContent = t; chip.textContent = t;
tagsEl.appendChild(chip); tagsEl.appendChild(chip);
@@ -1408,6 +1404,20 @@ const authorKey = name => deburr(name).replace(/[^a-z0-9 ]/g, ' ').split(/\s+/).
const subjectKey = t => deburr(String(t)).replace(/\s+/g, ' ').trim(); const subjectKey = t => deburr(String(t)).replace(/\s+/g, ' ').trim();
const SUBJECT_MIN = 20; const SUBJECT_MIN = 20;
// the catalogue repeats most subjects in English ("Railroads - Buildings and
// structures - Porto Velho (Rondônia, Brazil)" beside "Ferrovias - …"); keep the
// Portuguese side. An English-only record keeps what it has rather than none.
const EN_WORD = new RegExp('\\b(?:brazil|state|buildings?|structures|and|of|the|railroads?|rivers?|bridges|streets|church(?:es)?|photographs?|public|dwellings|portraits?|stations?|construction|region|waterfalls|plazas|mountains|women|history|life|hospitals?|views?|colon(?:y|ies)|slaves|panoramic|aerial|harbors?|ports?|forts?|islands?|beaches|houses|schools?|palaces?|squares?|paraguay|amazon|falls|lakes?|people|children|boats|ships|trains?|roads?|cities|city|towns?|landscapes?|factories|industry)\\b', 'i');
function subjectsOf(meta) {
const seen = new Set(), all = [];
[].concat((meta || {}).subject || []).forEach(t => {
const k = subjectKey(t);
if (k && !seen.has(k)) { seen.add(k); all.push(String(t).trim()); }
});
const pt = all.filter(t => !EN_WORD.test(t));
return pt.length ? pt : all;
}
function setupFilters(mapData) { function setupFilters(mapData) {
const entries = Object.values(mapData.map); const entries = Object.values(mapData.map);
const instCounts = new Map(), typeCounts = new Map(), authorGroups = new Map(), subjectGroups = new Map(); const instCounts = new Map(), typeCounts = new Map(), authorGroups = new Map(), subjectGroups = new Map();
@@ -1418,8 +1428,7 @@ function setupFilters(mapData) {
if (meta.community) instCounts.set(meta.community, (instCounts.get(meta.community) || 0) + 1); if (meta.community) instCounts.set(meta.community, (instCounts.get(meta.community) || 0) + 1);
const t = cleanType(meta.type); const t = cleanType(meta.type);
if (t) typeCounts.set(t, (typeCounts.get(t) || 0) + 1); if (t) typeCounts.set(t, (typeCounts.get(t) || 0) + 1);
new Set([].concat(meta.subject || []).map(subjectKey)).forEach(k => { subjectsOf(meta).map(subjectKey).forEach(k => {
if (!k) return;
subjectGroups.set(k, (subjectGroups.get(k) || 0) + 1); subjectGroups.set(k, (subjectGroups.get(k) || 0) + 1);
}); });
const a = cleanAuthor(meta.contributor); const a = cleanAuthor(meta.contributor);
@@ -1460,7 +1469,7 @@ function setupFilters(mapData) {
}); });
const subjectNames = new Map(); // key → a readable spelling const subjectNames = new Map(); // key → a readable spelling
entries.forEach(e => [].concat((e.meta || {}).subject || []).forEach(t => { entries.forEach(e => subjectsOf(e.meta).forEach(t => {
const k = subjectKey(t); const k = subjectKey(t);
if (k && subjectGroups.get(k) >= SUBJECT_MIN && !subjectNames.has(k)) subjectNames.set(k, String(t).trim()); if (k && subjectGroups.get(k) >= SUBJECT_MIN && !subjectNames.has(k)) subjectNames.set(k, String(t).trim());
})); }));
@@ -1502,7 +1511,7 @@ function setupFilters(mapData) {
const a = cleanAuthor(meta.contributor); const a = cleanAuthor(meta.contributor);
m.userData._author = a ? authorKey(a) : ''; m.userData._author = a ? authorKey(a) : '';
m.userData._type = cleanType(meta.type); m.userData._type = cleanType(meta.type);
m.userData._subjects = new Set([].concat(meta.subject || []).map(subjectKey)); m.userData._subjects = new Set(subjectsOf(meta).map(subjectKey));
// one haystack per piece: every metadata field, not a chosen few // one haystack per piece: every metadata field, not a chosen few
// the handle is the map's key, not a field of meta — it still has to be // the handle is the map's key, not a field of meta — it still has to be
// searchable (people paste a handle or its number straight into the box) // searchable (people paste a handle or its number straight into the box)