summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-07-03 11:12:42 +0200
committerYorhel <git@yorhel.nl>2016-07-03 11:12:42 +0200
commit92235222dba4e5d0c7713d53ef12e0f10e371b83 (patch)
tree685e370a7767882c7ac9d75a945a7d5143b73c88 /lib
parent7da2edeaa0f6cf7794f4f8f68960497dc1be893c (diff)
Charedit/traits: Prioritize exact match when finding traits
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Traits.pm3
-rw-r--r--lib/VNDB/Handler/Traits.pm14
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/VNDB/DB/Traits.pm b/lib/VNDB/DB/Traits.pm
index 45173f6e..f2eadaba 100644
--- a/lib/VNDB/DB/Traits.pm
+++ b/lib/VNDB/DB/Traits.pm
@@ -30,7 +30,8 @@ sub dbTraitGet {
my %where = (
$o{id} ? ( 't.id IN(!l)' => [ ref($o{id}) ? $o{id} : [$o{id}] ]) : (),
$o{group} ? ( 't.group = ?' => $o{group} ) : (),
- $o{noid} ? ( 't.id <> ?' => $o{noid} ) : (),
+ $o{noid} && ref($o{noid}) && @{$o{noid}} ? ('t.id NOT IN(!l)', [$o{noid}]) : (),
+ $o{noid} && !ref($o{noid}) ? ('t.id <> ?' => $o{noid}) : (),
defined $o{state} && $o{state} != -1 ? (
't.state = ?' => $o{state} ) : (),
!defined $o{state} && !$o{id} && !$o{name} ? (
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index adce5ef7..811815c3 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -409,14 +409,26 @@ sub traitxml {
);
return $self->resNotFound if $f->{_err} || (!$f->{q} && !$f->{id} && !$f->{id}[0]);
+ # First try an exact match
my($list, $np) = $self->dbTraitGet(
- !$f->{q} ? () : $f->{q} =~ /^i([1-9]\d*)/ ? (id => $1) : (search => $f->{q}),
+ !$f->{q} ? () : $f->{q} =~ /^i([1-9]\d*)/ ? (id => $1) : (name => $f->{q}),
$f->{id} && $f->{id}[0] ? (id => $f->{id}) : (),
results => $f->{r},
page => 1,
sort => 'group'
);
+ # Fill up the results with substring matches
+ if(!$np && $f->{q} && !($f->{id} && $f->{id}[0])) {
+ my($nlist, $nnp) = $self->dbTraitGet(
+ results => $f->{r}-@$list, page => 1,
+ search => $f->{q}, sort => 'group',
+ noid => [ map $_->{id}, @$list ]
+ );
+ $np = $nnp;
+ $list = [ @$list, @$nlist ];
+ }
+
$self->resHeader('Content-type' => 'text/xml; charset=UTF-8');
xml;
tag 'traits', more => $np ? 'yes' : 'no';