Skip to content

Instantly share code, notes, and snippets.

@willert
Created November 20, 2013 14:51
Show Gist options
  • Save willert/7564441 to your computer and use it in GitHub Desktop.
Save willert/7564441 to your computer and use it in GitHub Desktop.
sub ingredient : Chained(base) {
my ( $self, $ctx, $query_string, @rest ) = @_;
$query_string = join( q{/}, $query_string, @rest ) if @rest;
$query_string =~ s/\W+/ /g; # <-- da kommt dein sanitizer hin
my @suggestions;
goto RETURN_SUGGESTIONS unless $query_string;
my @search_terms = @{ $suggester->suggest( $query_string ) };
unshift @search_terms, $query_string;
my $query = $query_parser->parse( join( q{ OR }, @search_terms ));
my $hits = $searcher->hits(
query => $query,
num_wanted => 10,
sort_spec => $scorer,
);
while ( my $hit = $hits->next ) {
push @suggestions, $hit->{title};
}
RETURN_SUGGESTIONS:
$ctx->response->body( decode( utf8 => $json->objToJson(
\@suggestions
)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment