summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorkt <>2015-01-17 10:45:41 +0100
committerYorhel <git@yorhel.nl>2015-01-17 10:45:41 +0100
commit5bc52fc618cf200e82d320987a6c6829cf67bf1d (patch)
tree971a2df28615d0f575dfbc0b7c66eb5ae73b273d
parent1cc4307e0097877f0e2a26c03c372651a4eb88f4 (diff)
staff: Fix search to ignore spaces in Japanese names
-rw-r--r--lib/VNDB/DB/Staff.pm7
-rw-r--r--util/sql/staff.sql1
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Staff.pm b/lib/VNDB/DB/Staff.pm
index 3e26e360..2c8dae93 100644
--- a/lib/VNDB/DB/Staff.pm
+++ b/lib/VNDB/DB/Staff.pm
@@ -25,7 +25,12 @@ sub dbStaffGet {
$o{id} ? ( ref $o{id} ? ('s.id IN(!l)' => [$o{id}]) : ('s.id = ?' => $o{id}) ) : (),
$o{aid} ? ( ref $o{aid} ? ('sa.id IN(!l)' => [$o{aid}]) : ('sa.id = ?' => $o{aid}) ) : (),
$o{search} ?
- ( '(sa.name ILIKE ? OR sa.original ILIKE ?)', [ map '%%'.$o{search}.'%%', 1..2 ] ) : (),
+ $o{search} =~ /[\x{3000}-\x{9fff}\x{ff00}-\x{ff9f}]/ ?
+ # match against 'original' column only if search string contains any
+ # japanese character.
+ # note: more precise regex would be /[\p{Hiragana}\p{Katakana}\p{Han}]/
+ ( q|(sa.original LIKE ? OR translate(sa.original,' ','') LIKE ?)| => [ '%'.$o{search}.'%', ($o{search} =~ s/\s+//gr).'%' ] ) :
+ ( '(sa.name ILIKE ? OR sa.original ILIKE ?)' => [ map '%%'.$o{search}.'%%', 1..2 ] ) : (),
$o{char} ? ( 'LOWER(SUBSTR(sa.name, 1, 1)) = ?' => $o{char} ) : (),
defined $o{char} && !$o{char} ?
( '(ASCII(sa.name) < 97 OR ASCII(sa.name) > 122) AND (ASCII(sa.name) < 65 OR ASCII(sa.name) > 90)' => 1 ) : (),
diff --git a/util/sql/staff.sql b/util/sql/staff.sql
index cf452bcc..972765ea 100644
--- a/util/sql/staff.sql
+++ b/util/sql/staff.sql
@@ -59,6 +59,7 @@ ALTER TABLE vn_seiyuu ADD FOREIGN KEY (vid) REFERENCES vn_rev
CREATE INDEX vn_staff_vid ON vn_staff (vid);
CREATE INDEX vn_staff_aid ON vn_staff (aid);
+CREATE INDEX staff_alias_orig ON staff_alias (translate(original,' ',''));
CREATE TRIGGER hidlock_update BEFORE UPDATE ON staff FOR EACH ROW WHEN (OLD.latest IS DISTINCT FROM NEW.latest) EXECUTE PROCEDURE update_hidlock();