fix: improve archive search

This commit is contained in:
Floorb 2023-05-17 08:52:38 -04:00
parent 6f684e0283
commit 2bccaf408f
8 changed files with 32 additions and 11 deletions

View file

@ -229,13 +229,19 @@ const dumbFilterCallback = (datum, query) => {
return true; return true;
} }
if (datum.title.indexOf(query) !== -1) { const queryLower = query.toLowerCase();
if (queryLower === 'untagged' && datum.tags.length === 0) {
return true;
}
if (datum.title.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
/* this is inefficient */ /* this is inefficient */
for (const tag of datum.tags) { for (const tag of datum.tags) {
if (tag.name.toLowerCase() === query.toLowerCase()) { if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
} }

View file

@ -35,7 +35,10 @@ $pastes = Paste::with([
if (!empty($filter_value)) { if (!empty($filter_value)) {
$pastes = $pastes->where('title', 'LIKE', '%' . escapeLikeQuery($filter_value) . '%'); $pastes = $pastes->where('title', 'LIKE', '%' . escapeLikeQuery($filter_value) . '%')
->orWhereHas('tags', function($q) use ($filter_value) {
$q->where('name', 'LIKE', '%' . escapeLikeQuery($filter_value) . '%');
});
} }
$total_results = $pastes->count(); $total_results = $pastes->count();

View file

@ -274,13 +274,19 @@ const dumbFilterCallback = (datum, query) => {
return true; return true;
} }
if (datum.title.indexOf(query) !== -1) { const queryLower = query.toLowerCase();
if (queryLower === 'untagged' && datum.tags.length === 0) {
return true;
}
if (datum.title.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
/* this is inefficient */ /* this is inefficient */
for (const tag of datum.tags) { for (const tag of datum.tags) {
if (tag.name.toLowerCase() === query.toLowerCase()) { if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -274,13 +274,19 @@ const dumbFilterCallback = (datum, query) => {
return true; return true;
} }
if (datum.title.indexOf(query) !== -1) { const queryLower = query.toLowerCase();
if (queryLower === 'untagged' && datum.tags.length === 0) {
return true;
}
if (datum.title.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
/* this is inefficient */ /* this is inefficient */
for (const tag of datum.tags) { for (const tag of datum.tags) {
if (tag.name.toLowerCase() === query.toLowerCase()) { if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
return true; return true;
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long