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/Traits.pm | |
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/Traits.pm')
-rw-r--r-- | lib/VNDB/Handler/Traits.pm | 18 |
1 files changed, 3 insertions, 15 deletions
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'; |