Skip to content

Commit

Permalink
autocomplete_using_suggester: improve sorting by length
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Dec 15, 2016
1 parent 5f182e9 commit 9605d6c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -499,28 +499,46 @@ sub autocomplete_using_suggester {
}
);

my @docs
= map { $_->{text} } @{ $suggestions->{documentation}[0]{options} };
my %docs;
for my $d ( @{ $suggestions->{documentation}[0]{options} } ) {
next if exists $docs{ $d->{text} };
$docs{ $d->{text} } = $d->{score};
}

my @docs_uniq = sort { $docs{$b} <=> $docs{$a} } keys %docs;

my $data = $self->es->search(
{
index => $self->index->name,
type => 'file',
body => {
query => { match_all => {} },
query => {
filtered => {
query => {
function_score => {
script_score => {
script => {
lang => 'groovy',
file => 'prefer_shorter_module_names_400',
},
},
},
},
},
},
filter => {
bool => {
must => [
{ term => { indexed => 1 } },
{ term => { authorized => 1 } },
{ term => { status => 'latest' } },
{ terms => { 'documentation' => \@docs } },
{ terms => { 'documentation' => \@docs_uniq } },
],
}
}
},
},
fields => ['documentation'],
size => 10
size => 10,
}
);

Expand Down

0 comments on commit 9605d6c

Please sign in to comment.