Skip to content

Commit

Permalink
query fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monken committed Jul 12, 2014
1 parent 1bb1318 commit a7b7d9e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/MetaCPAN/Document/File.pm
Expand Up @@ -933,17 +933,21 @@ sub autocomplete {
my @query = split( /\s+/, $query );
my $should = [
map {
{ field => { 'documentation.analyzed' => "$_*" } },
{ field => { 'documentation.camelcase' => "$_*" } }
} grep {$_} @query
{ simple_query_string => {
fields => ['documentation.analyzed', 'documentation.camelcase'],
query => "$_*"
}
} } grep {$_} @query
];

# TODO: custom_score is deprecated in 0.90.4 in favor of function_score.
# As of 2013-10-27 we are still using 0.20.2 in production.
return $self->query(
{ custom_score => {
{ function_score => {
query => { bool => { should => $should } },
script => "_score - doc['documentation'].value.length()/100",
script_score => {
script => "_score - doc['documentation'].value.length()/100",
}
}
}
)->filter(
Expand Down
2 changes: 1 addition & 1 deletion t/server/controller/search/autocomplete.t
Expand Up @@ -13,7 +13,7 @@ test_psgi app, sub {
'GET' );
ok( my $json = eval { decode_json( $res->content ) }, 'valid json' );

my $got = [ map { $_->{fields}{documentation} }
my $got = [ map { @{$_->{fields}{documentation}} }
@{ $json->{hits}{hits} } ];

is_deeply $got, [
Expand Down
2 changes: 1 addition & 1 deletion t/server/controller/search/reverse_dependencies.t
Expand Up @@ -116,7 +116,7 @@ test_psgi app, sub {
);
ok( my $json = eval { decode_json( $res->content ) }, 'valid json' );
is( $json->{hits}->{total}, 1, 'total is 1' );
is( $json->{hits}->{hits}->[0]->{fields}->{distribution},
is( $json->{hits}->{hits}->[0]->{fields}->{distribution}->[0],
'Multiple-Modules-RDeps-A', 'filter worked' );
}
};
Expand Down

0 comments on commit a7b7d9e

Please sign in to comment.