From 5e195bed25ff9f77accc3f2d6fb8bc925ef8d853 Mon Sep 17 00:00:00 2001 From: hunterlang Date: Sat, 21 Apr 2012 16:03:30 -0400 Subject: [PATCH] update to fix alternativeto and add nginx override for randword --- lib/DDG/Spice/AlternativeTo.pm | 8 ++++---- lib/DDG/Spice/RandWord.pm | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/DDG/Spice/AlternativeTo.pm b/lib/DDG/Spice/AlternativeTo.pm index cef519d5b2..94406f5ff7 100644 --- a/lib/DDG/Spice/AlternativeTo.pm +++ b/lib/DDG/Spice/AlternativeTo.pm @@ -14,22 +14,22 @@ handle query_lc => sub { # license and platform specified - queries like: # -> free alternative to firefox for mac # -> opensource matlab for linux - return $2, "platform=".$3, "license=".$1; + return $2, "platform=".$3, "license=".$1.'/'; } elsif ($1 and $2) { # lincense secified only: # -> free nod32 # -> opensource alternative to omnigraffle - return $2, "license=".$1; + return $2, "license=".$1.'/'; } elsif ($3) { # platform specified: # -> TextMate for windows # -> alternative to vim for linux - return $2, "platform=".$3; + return $2, "platform=".$3.'/'; } elsif($2) { # license and platform not specified # in this case we need to match 'alternative(s) to': # -> alternative to firefox - return $2; + return $2.'/'; } } return; diff --git a/lib/DDG/Spice/RandWord.pm b/lib/DDG/Spice/RandWord.pm index 677f725744..0960ba3cde 100644 --- a/lib/DDG/Spice/RandWord.pm +++ b/lib/DDG/Spice/RandWord.pm @@ -1,16 +1,29 @@ package DDG::Spice::RandWord; use DDG::Spice; +sub nginx_conf { + my $api_key = $ENV{WORDNIK_API_KEY}; + $nginx_conf = <<"__END_OF_CONF__"; + +location ^~ /js/spice/rand_word/ { + rewrite ^$/js/spice/rand_word/(?:([0-9]+)\-([0-9]+)|) /v4/words.json/randomWord?minLength=$1&maxLength=$2&api_key=$api_key&callback=ddg_spice_rand_word break; + proxy_pass http://api.wordnik.com/; +} + +__END_OF_CONF__ +} + triggers any => "random", "word"; #spice is_memcached => 0; handle query_lc => sub { if ($_ =~ /^random word(?: ([0-9]+\-[0-9]+)|)$/) { if ($1) { - return qq(/iwrd/$1); + return $1; } else { - return qq(/iwrd/); + return; } # $is_kill_pre_results = 1; } + return; }; 1;