summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2023-03-24 13:21:44 +0100
committerYorhel <git@yorhel.nl>2023-03-24 13:21:46 +0100
commit6bb39935d38f3ba5839f0784c8be1724d6a2783c (patch)
treed121393debbb0b089e4a760d509f1e4e72944b34
parentdef661a4cf5cda99e17e81f6efeb6c18ebf69c1c (diff)
*::Elm: Don't throw error on "empty" search queries
Queries that normalize to nothing (e.g. ".") do not really need to throw an error - it's not a bug in the front-end code - and should also not prevent such entries from being created.
-rw-r--r--lib/VNWeb/Chars/Elm.pm4
-rw-r--r--lib/VNWeb/Producers/Elm.pm5
-rw-r--r--lib/VNWeb/Staff/Elm.pm5
-rw-r--r--lib/VNWeb/TT/Elm.pm8
-rw-r--r--lib/VNWeb/VN/Elm.pm5
5 files changed, 12 insertions, 15 deletions
diff --git a/lib/VNWeb/Chars/Elm.pm b/lib/VNWeb/Chars/Elm.pm
index 5d9901dc..ad8d723c 100644
--- a/lib/VNWeb/Chars/Elm.pm
+++ b/lib/VNWeb/Chars/Elm.pm
@@ -5,13 +5,13 @@ use VNWeb::Prelude;
elm_api Chars => undef, { search => { searchquery => 1 } }, sub {
my $q = shift->{search};
- my $l = tuwf->dbPagei({ results => 15, page => 1 },
+ my $l = $q ? tuwf->dbPagei({ results => 15, page => 1 },
'SELECT c.id, c.title[1+1] AS title, c.title[1+1+1+1] AS alttitle, c.main, cm.title[1+1] AS main_title, cm.title[1+1+1+1] AS main_alttitle
FROM', charst, 'c', $q->sql_join('c', 'c.id'), '
LEFT JOIN', charst, 'cm ON cm.id = c.main
WHERE NOT c.hidden
ORDER BY sc.score DESC, c.sorttitle
- ');
+ ') : [];
for (@$l) {
$_->{main} = { id => $_->{main}, title => $_->{main_title}, alttitle => $_->{main_alttitle} } if $_->{main};
delete $_->{main_title};
diff --git a/lib/VNWeb/Producers/Elm.pm b/lib/VNWeb/Producers/Elm.pm
index e235d015..8aee07e3 100644
--- a/lib/VNWeb/Producers/Elm.pm
+++ b/lib/VNWeb/Producers/Elm.pm
@@ -8,14 +8,13 @@ elm_api Producers => undef, {
}, sub {
my($data) = @_;
my @q = grep $_, $data->{search}->@*;
- die "No query" if !@q;
- elm_ProducerResult tuwf->dbPagei({ results => 15, page => 1 },
+ elm_ProducerResult @q ? tuwf->dbPagei({ results => 15, page => 1 },
'SELECT p.id, p.title[1+1] AS name, p.title[1+1+1+1] AS altname, p.hidden
FROM', producerst, 'p', VNWeb::Validate::SearchQuery::sql_joina(\@q, 'p', 'p.id'),
$data->{hidden} ? () : 'WHERE NOT p.hidden', '
ORDER BY sc.score DESC, p.sorttitle
- ');
+ ') : [];
};
1;
diff --git a/lib/VNWeb/Staff/Elm.pm b/lib/VNWeb/Staff/Elm.pm
index 6bc7f9b8..0820ee5e 100644
--- a/lib/VNWeb/Staff/Elm.pm
+++ b/lib/VNWeb/Staff/Elm.pm
@@ -7,14 +7,13 @@ elm_api Staff => undef, {
}, sub {
my($data) = @_;
my @q = grep $_, $data->{search}->@*;
- die "No query" if !@q;
- elm_StaffResult tuwf->dbPagei({ results => 15, page => 1 },
+ elm_StaffResult @q ? tuwf->dbPagei({ results => 15, page => 1 },
'SELECT s.id, s.lang, s.aid, s.title[1+1], s.title[1+1+1+1] as alttitle
FROM', staff_aliast, 's', VNWeb::Validate::SearchQuery::sql_joina(\@q, 's', 's.id', 's.aid'), '
WHERE NOT s.hidden
ORDER BY sc.score DESC, s.sorttitle
- ');
+ ') : [];
};
1;
diff --git a/lib/VNWeb/TT/Elm.pm b/lib/VNWeb/TT/Elm.pm
index 3f8264b0..b3eaec83 100644
--- a/lib/VNWeb/TT/Elm.pm
+++ b/lib/VNWeb/TT/Elm.pm
@@ -5,25 +5,25 @@ use VNWeb::Prelude;
elm_api Tags => undef, { search => { searchquery => 1 } }, sub {
my $q = shift->{search};
- elm_TagResult tuwf->dbPagei({ results => 15, page => 1 },
+ elm_TagResult $q ? tuwf->dbPagei({ results => 15, page => 1 },
'SELECT t.id, t.name, t.searchable, t.applicable, t.hidden, t.locked
FROM tags t', $q->sql_join('g', 't.id'), '
WHERE NOT (t.hidden AND t.locked)
ORDER BY sc.score DESC, t.name
- ')
+ ') : [];
};
elm_api Traits => undef, { search => { searchquery => 1 } }, sub {
my $q = shift->{search};
- elm_TraitResult tuwf->dbPagei({ results => 15, page => 1 },
+ elm_TraitResult $q ? tuwf->dbPagei({ results => 15, page => 1 },
'SELECT t.id, t.name, t.searchable, t.applicable, t.defaultspoil, t.hidden, t.locked, g.id AS group_id, g.name AS group_name
FROM traits t', $q->sql_join('i', 't.id'), '
LEFT JOIN traits g ON g.id = t.group
WHERE NOT (t.hidden AND t.locked)
ORDER BY sc.score DESC, t.name
- ')
+ ') : [];
};
1;
diff --git a/lib/VNWeb/VN/Elm.pm b/lib/VNWeb/VN/Elm.pm
index 573371eb..91d4523a 100644
--- a/lib/VNWeb/VN/Elm.pm
+++ b/lib/VNWeb/VN/Elm.pm
@@ -8,14 +8,13 @@ elm_api VN => undef, {
}, sub {
my($data) = @_;
my @q = grep $_, $data->{search}->@*;
- die "No query" if !@q;
- elm_VNResult tuwf->dbPagei({ results => $data->{hidden}?50:15, page => 1 },
+ elm_VNResult @q ? tuwf->dbPagei({ results => $data->{hidden}?50:15, page => 1 },
'SELECT v.id, v.title[1+1] AS title, v.hidden
FROM', vnt, 'v', VNWeb::Validate::SearchQuery::sql_joina(\@q, 'v', 'v.id'),
$data->{hidden} ? () : 'WHERE NOT v.hidden', '
ORDER BY sc.score DESC, v.sorttitle
- ');
+ ') : [];
};
1;