Skip to content

Instantly share code, notes, and snippets.

@smeghead
Created June 8, 2011 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeghead/1013825 to your computer and use it in GitHub Desktop.
Save smeghead/1013825 to your computer and use it in GitHub Desktop.
AnyEvent-Groonga filter-support patch
diff --git a/lib/AnyEvent/Groonga.pm b/lib/AnyEvent/Groonga.pm
index fcf0a4c..2e2ded1 100644
--- a/lib/AnyEvent/Groonga.pm
+++ b/lib/AnyEvent/Groonga.pm
@@ -221,7 +221,7 @@ sub _generate_groonga_command {
if ( $command eq 'load' && $key eq 'values' ) {
$value = $self->_load_filter($value);
}
- elsif ( $command eq 'select' && $key eq 'query' ) {
+ elsif ( $command eq 'select' && ( $key eq 'query' || $key eq 'filter' )) {
$value = $self->_select_filter($value);
}
elsif ( ref $value eq 'ARRAY' ) {
diff --git a/t/04_tut.t b/t/04_tut.t
index 7fd5fd9..417d7f4 100644
--- a/t/04_tut.t
+++ b/t/04_tut.t
@@ -1,5 +1,6 @@
use strict;
use warnings;
+use lib '../lib';
use AnyEvent::Groonga;
use Test::More;
use FindBin;
@@ -16,7 +17,7 @@ unless ($groonga_path and -e $groonga_path) {
plan skip_all => "groonga is not installed.";
}
else{
- plan tests => 20;
+ plan tests => 21;
}
`$groonga_path -n $test_database_path quit`;
@@ -422,6 +423,37 @@ is_deeply(
]
);
+# filter test.
+$result = $g->call(
+ select => {
+ table => "Site",
+ query => 'title:@test',
+ filter => '_id > 1 && _id < 5',
+ output_columns => [qw(_id _score title)],
+ sortby => [qw(_score _id)],
+ }
+)->recv;
+
+is_deeply(
+ $result->items,
+ [
+ {
+ '_score' => 3,
+ '_id' => 2,
+ 'title' => 'test record 2.'
+ },
+ {
+ '_score' => 3,
+ '_id' => 4,
+ 'title' => 'test record four.'
+ },
+ {
+ '_score' => 4,
+ '_id' => 3,
+ 'title' => 'test test record three.'
+ }
+ ]
+);
sub _cleanup {
my @files = glob( File::Spec->catfile( $FindBin::RealBin, "data", "*" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment