diff options
author | Yorhel <git@yorhel.nl> | 2016-07-03 15:14:49 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2016-07-03 15:14:49 +0200 |
commit | e2cd8349be295dff3fd2b07f1b1c8282377a1ffd (patch) | |
tree | 6201ae5b4635359222999b4f82b4227f8f26116e /lib/VNDB/Handler | |
parent | 5648ca9997e4d986799bccd877deaf72b47e48a0 (diff) |
Generalize substring search relevance + apply to most dropdown searches
This is a generalization of the search improvements made in
7da2edeaa0f6cf7794f4f8f68960497dc1be893c and
92235222dba4e5d0c7713d53ef12e0f10e371b83
And has been applied to the dropdown searches for producers, staff, tags
and traits.
For all those searches, exact matches are listed first, followed by
prefix matches, and then substring matches. Relevance is currently only
based on the primary name/title and ignores aliases (except for staff).
This is fixable, but not trivial, and I'm not sure it's all that useful.
Diffstat (limited to 'lib/VNDB/Handler')
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/Staff.pm | 16 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/Traits.pm | 18 |
4 files changed, 6 insertions, 32 deletions
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index f3a167c2..8371d9a1 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -406,7 +406,7 @@ sub pxml { $q = $q->{q}; my($list, $np) = $self->dbProducerGet( - $q =~ /^p([1-9]\d*)/ ? (id => $1) : (search => $q), + $q =~ /^p([1-9]\d*)/ ? (id => $1) : (search => $q, sort => 'search'), results => 10, page => 1, ); diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm index 24edf5ad..378bbd91 100644 --- a/lib/VNDB/Handler/Staff.pm +++ b/lib/VNDB/Handler/Staff.pm @@ -370,25 +370,11 @@ sub staffxml { my $q = $self->formValidate({ get => 'q', required => 0, maxlength => 500 }); return $self->resNotFound if $q->{_err} || !$q->{q}; - # Prefixing name with '=' forces exact matching, old behaviour, not very useful anymore. - my $exact = $q->{q} =~ s/^=//; - - # Try exact match first, so exact match is always first result my($list, $np) = $self->dbStaffGet( + $q->{q} =~ /^s([1-9]\d*)/ ? (id => $1) : $q->{q} =~ /^=(.+)/ ? (exact => $1) : (search => $q->{q}, sort => 'search'), results => 10, page => 1, - $q->{q} =~ /^s([1-9]\d*)/ ? (id => $1) : (exact => $q->{q}), ); - # Append results of a substring match - if(!$np && !$exact) { - my($nlist, $nnp) = $self->dbStaffGet( - results => 10-@$list, page => 1, search => $q->{q}, - notid => [ map $_->{id}, @$list ], - ); - $np = $nnp; - $list = [ @$list, @$nlist ]; - } - $self->resHeader('Content-type' => 'text/xml; charset=UTF-8'); xml; tag 'staff', more => $np ? 'yes' : 'no'; diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index 61a3e2b3..43215fde 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -743,7 +743,7 @@ sub tagxml { return $self->resNotFound if $f->{_err} || (!$f->{q} && !$f->{id} && !$f->{id}[0]); my($list, $np) = $self->dbTagGet( - !$f->{q} ? () : $f->{q} =~ /^g([1-9]\d*)/ ? (id => $1) : $f->{q} =~ /^name:(.+)$/ ? (name => $1) : (search => $f->{q}), + !$f->{q} ? () : $f->{q} =~ /^g([1-9]\d*)/ ? (id => $1) : $f->{q} =~ /^=(.+)$/ ? (name => $1) : (search => $f->{q}, sort => 'search'), $f->{id} && $f->{id}[0] ? (id => $f->{id}) : (), results => 15, page => 1, diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm index 811815c3..0f4169aa 100644 --- a/lib/VNDB/Handler/Traits.pm +++ b/lib/VNDB/Handler/Traits.pm @@ -409,26 +409,14 @@ 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) : (name => $f->{q}), - $f->{id} && $f->{id}[0] ? (id => $f->{id}) : (), results => $f->{r}, page => 1, - sort => 'group' + sort => 'group', + !$f->{q} ? () : $f->{q} =~ /^i([1-9]\d*)/ ? (id => $1) : (search => $f->{q}, sort => 'search'), + $f->{id} && $f->{id}[0] ? (id => $f->{id}) : (), ); - # 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'; |