Index: trunk/lib/Bookmarks.pm
===================================================================
--- trunk/lib/Bookmarks.pm	(revision 70)
+++ trunk/lib/Bookmarks.pm	(revision 71)
@@ -2,8 +2,11 @@
 
 use Moose;
+
 use SQL::Interp qw{:all};
 use URI;
+
 use Bookmark;
 use Bookmarks::List;
+use Bookmarks::Search;
 
 has dbh      => ( is => 'rw' );
@@ -73,18 +76,12 @@
     my $self = shift;
     my $params = shift;
-    my $query = $params->{query};
-    my $tags = $params->{tag} || [];
-    my $limit = $params->{limit};
-    my $offset = $params->{offset};
+    my $search = Bookmarks::Search->new($params);
 
     # build the query
     my @sql;
 
-    if (!ref $tags) {
-        $tags = [ $tags ];
-    }
-    if (@$tags) {
+    if (@{ $search->tags }) {
         my $intersect = 0;
-        for my $tag (@{ $tags }) {
+        for my $tag (@{ $search->tags }) {
             push @sql, 'intersect' if $intersect;
             push @sql, 'select resources.*, bookmarks.* from resources join bookmarks on resources.uri = bookmarks.uri';
@@ -95,14 +92,14 @@
         push @sql, 'select * from resources join bookmarks on resources.uri = bookmarks.uri';
     }
-    if ($query) {
-        push @sql, (@$tags ? 'and' : 'where'), 'title like', \"%$query%";
+    if ($search->query) {
+        my $fuzzy_match = '%' . $search->query . '%';
+        push @sql, (@{ $search->tags } ? 'and' : 'where'), 'title like', \$fuzzy_match;
     }
     push @sql, 'order by ctime desc';
-    push @sql, ('limit', \$limit) if $limit;
+    push @sql, ('limit', \$search->limit) if $search->limit;
     # an offset is only allowed if we have a limit clause
-    push @sql, ('offset', \$offset) if $limit && $offset;
+    push @sql, ('offset', \$search->offset) if $search->limit && $search->offset;
 
     my ($sql, @bind) = sql_interp(@sql);
-    #die $sql;
 
     my $sth_resource = $self->dbh->prepare($sql);
@@ -119,8 +116,5 @@
     return Bookmarks::List->new({
         bookmarks => $self,
-        tags      => $tags,
-        query     => $query,
-        limit     => $limit,
-        offset    => $offset,
+        search    => $search,
         results   => \@resources,
     });
@@ -147,27 +141,25 @@
     my $self = shift;
     my $params = shift;
-    my $query = $params->{query};
-    my $tags = $params->{tag} || [];
-    if (!ref $tags) {
-        $tags = [ $tags ];
-    }
+    my $search = $params->{search};
+
     my @sql;
 
     push @sql, 'select tag, count(tag) as count from tags';
-    push @sql, 'join resources on tags.uri = resources.uri' if $query;
+    push @sql, 'join resources on tags.uri = resources.uri' if $search->query;
 
     # build the where clause
-    if (@$tags) {
+    if (@{ $search->tags }) {
         push @sql, 'where tags.uri in (';
         my $intersect = 0;
-        for my $tag (@{ $tags }) {
+        for my $tag (@{ $search->tags }) {
             push @sql, 'intersect' if $intersect;
             push @sql, 'select uri from tags where tag = ', \$tag;
             $intersect++;
         }
-        push @sql, ') and tag not in ', $tags, '';
-    }
-    if ($query) {
-        push @sql, (@$tags ? 'and' : 'where'), 'title like', \"%$query%";
+        push @sql, ') and tag not in ', $search->tags, '';
+    }
+    if ($search->query) {
+        my $fuzzy_match = '%' . $search->query . '%';
+        push @sql, (@{ $search->tags } ? 'and' : 'where'), 'title like', \$fuzzy_match;
     }
 
Index: trunk/lib/Bookmarks/Controller.pm
===================================================================
--- trunk/lib/Bookmarks/Controller.pm	(revision 70)
+++ trunk/lib/Bookmarks/Controller.pm	(revision 71)
@@ -85,5 +85,5 @@
     my $list = $self->bookmarks->get_bookmarks({
         query  => $query,
-        tag    => \@tags,
+        tags   => \@tags,
         limit  => $limit,
         offset => $offset,
@@ -104,5 +104,5 @@
 
     # construct a feed from the most recent 12 bookmarks
-    my $list = $self->bookmarks->get_bookmarks({ query => $query, tag => \@tags, limit => 12 });
+    my $list = $self->bookmarks->get_bookmarks({ query => $query, tags => \@tags, limit => 12 });
     return $list->as_atom;
 }
Index: trunk/lib/Bookmarks/List.pm
===================================================================
--- trunk/lib/Bookmarks/List.pm	(revision 70)
+++ trunk/lib/Bookmarks/List.pm	(revision 71)
@@ -6,12 +6,13 @@
 use HTTP::Date qw{time2iso time2isoz};
 
-has bookmarks => (is => 'ro');
-has query  => (is => 'ro');
-has tags   => (
+has bookmarks => (
     is => 'ro',
-    default => sub { [] },
+    isa => 'Bookmarks',
 );
-has limit  => (is => 'ro');
-has offset => (is => 'ro');
+has search => (
+    is => 'ro',
+    isa => 'Bookmarks::Search',
+    handles => [qw{query tags limit offset}],
+);
 has results => ( is => 'ro' );
 has title => (
@@ -182,8 +183,5 @@
 
     my @all_tags = $self->bookmarks->get_tags({ selected => @{ $self->tags }[0] });
-    my @cotags = $self->bookmarks->get_cotags({
-        query  => $self->query,
-        tag    => $self->tags,
-    });
+    my @cotags = $self->bookmarks->get_cotags({ search => $self->search });
 
     $template->process(
Index: trunk/lib/Bookmarks/Search.pm
===================================================================
--- trunk/lib/Bookmarks/Search.pm	(revision 71)
+++ trunk/lib/Bookmarks/Search.pm	(revision 71)
@@ -0,0 +1,14 @@
+package Bookmarks::Search;
+
+use Moose;
+
+has query  => (is => 'ro');
+has tags   => (
+    is => 'ro',
+    default => sub { [] },
+);
+has limit  => (is => 'ro');
+has offset => (is => 'ro');
+
+# module return
+1;
