[Jifty-commit] r2032 - in jifty/trunk: lib/Jifty/Action/Record
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Oct 19 16:54:25 EDT 2006
Author: nelhage
Date: Thu Oct 19 16:54:24 2006
New Revision: 2032
Modified:
jifty/trunk/lib/Jifty/Action/Record/Search.pm
jifty/trunk/t/TestApp/t/12-search.t
Log:
Adding an option to search the contents of any text field
Modified: jifty/trunk/lib/Jifty/Action/Record/Search.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Search.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record/Search.pm Thu Oct 19 16:54:24 2006
@@ -102,6 +102,8 @@
}
}
+ $args->{contains} = {type => 'text', label => 'Any field contains'};
+
return $self->_cached_arguments($args);
}
@@ -126,6 +128,7 @@
$collection->unlimit;
for my $field (grep {$self->has_argument($_)} $self->argument_names) {
+ next if $field eq 'contains';
my $value = $self->argument_value($field);
my $column = $self->record->column($field);
@@ -175,6 +178,19 @@
}
}
+ if($self->has_argument('contains')) {
+ my $any = $self->argument_value('contains');
+ for my $col ($self->record->columns) {
+ if($col->type =~ /(?:text|varchar)/) {
+ $collection->limit(column => $col->name,
+ value => "%$any%",
+ operator => 'LIKE',
+ entry_aggregator => 'OR',
+ subclause => 'contains');
+ }
+ }
+ }
+
$self->result->content(search => $collection);
$self->result->success;
}
Modified: jifty/trunk/t/TestApp/t/12-search.t
==============================================================================
--- jifty/trunk/t/TestApp/t/12-search.t (original)
+++ jifty/trunk/t/TestApp/t/12-search.t Thu Oct 19 16:54:24 2006
@@ -43,7 +43,7 @@
ok($user->create(
name => 'third_user',
- email => 'test3 at not.a.domain',
+ email => 'test3 at test2.com',
password => 'hahaha',
created_on => '1999-12-31 23:59'
),
@@ -192,3 +192,23 @@
isa_ok($result, 'Jifty::Collection');
is($result->count, 1);
is($result->first->name, 'third_user');
+
+# Searching on any field
+$search->argument_values({contains => 'test2'});
+$search->run;
+
+$result = $search->result->content('search');
+
+isa_ok($result, 'Jifty::Collection');
+is($result->count, 2);
+is($result->items_array_ref->[0]->name, 'test2');
+is($result->items_array_ref->[1]->name, 'third_user');
+
+
+$search->argument_values({contains => 'test2', email_contains => 'localhost'});
+$search->run;
+
+$result = $search->result->content('search');
+
+isa_ok($result, 'Jifty::Collection');
+is($result->count, 0);
More information about the Jifty-commit
mailing list