implement OR operator for text search

Этот коммит содержится в:
higsch 2020-10-22 00:22:46 +02:00
родитель d7fd372826
Коммит a4c655ef36
7 изменённых файлов: 15 добавлений и 9 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -53,7 +53,7 @@
function highlight(s) { function highlight(s) {
if (!$textSearchFilter || $textSearchFilter === '') return s; if (!$textSearchFilter || $textSearchFilter === '') return s;
return s.replace(new RegExp($textSearchFilter, 'gi'), (match) => `<span class="highlighted">${match}</span>`); return s.replace(new RegExp($textSearchFilter.toLowerCase().split(' or ').join('|'), 'gi'), (match) => `<span class="highlighted">${match}</span>`);
} }
$: if (showTooltip) { $: if (showTooltip) {

Просмотреть файл

@ -75,7 +75,7 @@
.map((d) => ({ .map((d) => ({
...d, ...d,
recentylAdded: Math.ceil(((new Date()) - d.timestamp) / (1000 * 60 * 60 * 24)) <= observeDays, recentylAdded: Math.ceil(((new Date()) - d.timestamp) / (1000 * 60 * 60 * 24)) <= observeDays,
search: [d.shortTitle, d.shortDescription, d.platforms, d.methods, d.sourceNation, d.source, d.sourceCategory].flat().join('__').toUpperCase(), search: [d.shortTitle, d.shortDescription, d.platforms, d.methods, d.sourceNation, d.source, d.sourceCategory].flat().join('__').toLowerCase(),
show: false show: false
})); }));

Просмотреть файл

@ -42,7 +42,13 @@ export const haveOverlap = (filter, arr) =>
export const withinRange = (arr, num) => num >= arr[0] && num <= arr[1]; export const withinRange = (arr, num) => num >= arr[0] && num <= arr[1];
// check, if a search string (filter) is included in a string // check, if a search string (filter) is included in a string
export const includesTextSearch = (filter, s) => s.indexOf(filter.toUpperCase()) > -1; export const includesTextSearch = (filter, s) => {
const filterArr = filter.toLowerCase().split(' or ');
if (filterArr.length === 0) return true;
return filterArr.some((f) => {
return s.indexOf(f) > -1;
});
};
// check if case id filter is set and if id is matching // check if case id filter is set and if id is matching
export const isCaseId = (filter, id) => filter === undefined ? true : (filter === id); export const isCaseId = (filter, id) => filter === undefined ? true : (filter === id);

Просмотреть файл

@ -11,7 +11,7 @@ export const urlFromFilters = (disinformantNations,
contextData, contextData,
caseId = '') => { caseId = '') => {
const params = { const params = {
ts: textSearch, ts: encodeURIComponent(textSearch),
as: [attributionScores[0], attributionScores[1]].join(';'), as: [attributionScores[0], attributionScores[1]].join(';'),
f: filtersToHex([disinformantNations, platforms, methods, sources, sourceCategories, contextData]), f: filtersToHex([disinformantNations, platforms, methods, sources, sourceCategories, contextData]),
id: caseId id: caseId
@ -43,7 +43,7 @@ export const parseUrl = (hash) => {
sourceCategories: binaryToBool(hexToBinary(sourceCategories)), sourceCategories: binaryToBool(hexToBinary(sourceCategories)),
contextData: binaryToBool(hexToBinary(contextData)), contextData: binaryToBool(hexToBinary(contextData)),
caseId: caseId === '' ? undefined : +caseId, caseId: caseId === '' ? undefined : +caseId,
textSearch, textSearch: decodeURIComponent(textSearch),
attributionScores: attributionScores.split(';').map((d) => +d) attributionScores: attributionScores.split(';').map((d) => +d)
}; };
}; };