Created
December 3, 2016 14:15
-
-
Save ranguard/810330bbf60193fc266252d1b91f954e to your computer and use it in GitHub Desktop.
suggest for autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Mapping | |
```json | |
"suggest": { | |
"type" : "completion", | |
"analyzer" : "simple", | |
"search_analyzer" : "simple", | |
"payloads" : true | |
}, | |
``` | |
### MetaCPAN::Document::File - adding the data at import time | |
```perl | |
has suggest => ( | |
required => 1, | |
is => 'ro', | |
lazy => 1, | |
builder => '_build_suggest', | |
# index => 'not_analyzed', | |
); | |
sub _build_suggest { | |
my $self = shift; | |
my $doc = $self->documentation; | |
return unless $doc; | |
my $weight = 1000 - length($doc); | |
return { | |
input => [ $doc ], | |
payload => { doc_name => $doc }, | |
weight => $weight | |
} | |
} | |
``` | |
### Running a query | |
```sh | |
curl -X POST 'localhost:9900/cpan/_suggest?pretty' -d '{ | |
"my-suggest" : { | |
"text" : "multiple::modu", | |
"completion" : { | |
"field" : "suggest" | |
} | |
} | |
}' | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment