Index: server/trunk/web/lib/Sophie/Controller/Search.pm
===================================================================
--- server/trunk/web/lib/Sophie/Controller/Search.pm	(revision 127)
+++ server/trunk/web/lib/Sophie/Controller/Search.pm	(revision 128)
@@ -328,210 +328,10 @@
 }
 
-sub bydep : XMLRPCPath('/search/rpm/bydep') {
-    my ( $self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_;
-    $searchspec ||= {};
-
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-
-    my $deprs = $c->model('Base::Deps')->search(
-        {
-            deptype => $deptype,
-            depname => $depname,
-            ($depsense
-                ? (-nest => \[
-                    'rpmdepmatch(flags, evr, rpmsenseflag(?), ?)',
-                    [ plain_text => $depsense],
-                    [ plain_text => $depevr ]
-                ])
-            : ()),
-        }
-    )->get_column('pkgid');
-    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
-        {
-            -and => [ 
-                (exists($searchspec->{src})
-                    ? { issrc => $searchspec->{src} ? 1 : 0 }
-                    : ()),
-                { pkgid => 
-                    { IN => $deprs->as_query, },
-                },
-                $distrs
-                    ? { pkgid => { IN => $distrs->get_column('pkgid')->as_query, }, }
-                    : (),
-            ]     
-        },
-    );
-    $c->forward('format_search', $searchspec);
-}
-
-sub byfile : XMLRPCPath('/search/rpm/byfile') {
-    my ( $self, $c, $searchspec, $file) = @_;
-    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
-    $searchspec ||= {};
-
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-    my $filers = $c->model('Base')->resultset('Files')
-    ->search({
-            ($dirname
-                ? (dirname => $dirname)
-                : ()),
-            basename => $basename,
-        })
-    ->get_column('pkgid');
-    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
-        {
-            -and => [ 
-                (exists($searchspec->{src})
-                    ? { issrc => $searchspec->{src} ? 1 : 0 }
-                    : ()),
-                { pkgid => 
-                    { IN => $filers->as_query, },
-                },
-                $distrs
-                    ? { pkgid => { IN => $distrs->get_column('pkgid')->as_query, }, }
-                    : (),
-            ]     
-        },
-    );
-    $c->forward('format_search', $searchspec);
-}
-
-sub fuzzy : XMLRPCPath('/search/rpm/fuzzy') {
-    my ($self, $c, $searchspec, $name) = @_;
-    $searchspec ||= {};
-
-    my $deprs = $c->model('Base')->resultset('Deps')->search(
-        { deptype => 'P', depname => { '~*' => $name } }
-    )->get_column('pkgid');
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-
-    $c->stash->{rs} = 
-
-        $c->model('Base')->resultset('Rpms')->search(
-        {
-            -and => [
-                (exists($searchspec->{src})
-                    ? { issrc => $searchspec->{src} ? 1 : 0 }
-                    : ()),
-                { -or => [
-                    { name => 
-                        { '~*' => $name, },
-                    },
-#                    { pkgid =>
-#                        { IN => $deprs->as_query, },
-#                    },
-                     ]
-                },
-                $distrs
-                    ? { pkgid => { IN => $distrs->get_column('pkgid')->as_query, }, }
-                    : (),
-            ]     
-        },
-    );
-    
-    $c->forward('format_search', $searchspec);
-}
-
-sub quick : XMLRPCPath('/search/rpm/quick') {
-    my ($self, $c, $searchspec, @keywords) = @_;
-    $searchspec ||= {};
-    my $tsquery = join(' & ', map { $_ =~ s/ /\\ /g; $_ } @keywords);
-    
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-
-    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
-            {
-                -or => [
-#                    { -nest => \[
-#                        "to_tsvector('english', description) @@ to_tsquery(?)",
-#                        [ plain_text => $tsquery],
-#                    ], },
-                    {
-                    name => { '~*' => [ @keywords ] },
-                    },
-                ],
-            (exists($searchspec->{src})
-                ? (issrc => $searchspec->{src} ? 1 : 0)
-                : ()),
-            ($distrs 
-                ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
-                : ()),
-        },
-    );
-    $c->forward('format_search', $searchspec);
-}
-
-sub description : XMLRPCPath('/search/rpm/description') {
-    my ($self, $c, $searchspec, @keywords) = @_;
-    $searchspec ||= {};
-    my $tsquery = join(' & ', map { $_ =~ s/ /\\ /g; $_ } @keywords);
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
-        {
-            -nest => \[
-                    "to_tsvector('english', description) @@ to_tsquery(?)",
-                    [ plain_text => $tsquery],
-                ],
-                (exists($searchspec->{src})
-                    ? (issrc => $searchspec->{src} ? 1 : 0)
-                    : ()),
-                ($distrs 
-                    ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
-                    : ()),
-        },
-        {
-            select => [ 
-                "ts_rank_cd(to_tsvector('english', description),to_tsquery(?)) as rank",
-                'pkgid'
-            ],
-            bind => [ $tsquery ], 
-            order_by => [ 'rank desc', 'name', 'evr using >>', 'issrc' ],
-        },
-    )->as_subselect_rs;
-    $c->forward('format_search', $searchspec);
-}
-
-sub file_search : XMLRPCPath('/search/file/byname') {
-    my ( $self, $c, $searchspec, $file) = @_;
-    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
-    $searchspec ||= {};
-
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-    my @col = qw(dirname basename md5 size pkgid count);
-    $c->stash->{rs} = $c->model('Base::Files')
-    ->search(
-        {
-            -and => [
-                ($dirname
-                    ? (dirname => $dirname)
-                    : ()),
-                basename => $basename,
-                ($searchspec->{content} ? { has_content => 1 } : ()),
-                ($distrs 
-                    ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
-                    : ()),
-            ],
-        },
-        {
-            'select' => [ 'contents is NOT NULL as has_content',
-                'rpmfilesmode(mode) as perm', @col, '"group"',
-                '"user"' ],
-            as => [ qw(has_content perm), @col,
-                'group', 'user' ],
-        }
-    );
-    
-    $c->stash->{column} = [
-        @col, qw(has_content perm user group)
-    ];
-    
-    $c->forward('format_search', $searchspec);
-}
-
-sub dep_search : XMLRPCPath('/search/dep/match') {
-    my ($self, $c, $searchspec, $deptype, $depname, $depsense, $depevr) = @_;
-
-    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
-    $c->stash->{rs} = $c->model('Base::Deps')->search(
+sub deps_rs : Private {
+    my ($self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_;
+
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    return $c->model('Base::Deps')->search(
         {
             -and => [
@@ -557,8 +357,197 @@
         },
         {
-            'select' => [ 'rpmsenseflag("flags")', qw(depname evr flags pkgid) ],
-            'as'     => [ qw(sense name evr flags pkgid) ],
+            '+select' => [ { rpmsenseflag => 'flags' }, 'depname', ],
+            '+as'     => [ qw(sense name) ],
 
         }
+    );
+}
+
+sub file_rs : Private {
+    my ( $self, $c, $searchspec, $file) = @_;
+    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
+    $searchspec ||= {};
+
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    return $c->model('Base::Files')->search(
+        {
+            -and => [
+                ($dirname
+                    ? (dirname => $dirname)
+                    : ()),
+                basename => $basename,
+                ($searchspec->{content} ? { has_content => 1 } : ()),
+                ($distrs 
+                    ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
+                    : ()),
+            ],
+        },
+        {
+            '+select' => [
+                'contents is NOT NULL as has_content',
+                { rpmfilesmode => 'mode' },
+            ],
+            '+as' => [ qw(has_content perm), ],
+        }
+    );
+}
+
+sub bydep : XMLRPCPath('/search/rpm/bydep') {
+    my ( $self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_;
+    $searchspec ||= {};
+
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    my $deprs = $c->forward(
+        'deps_rs', [ 
+            $searchspec, $deptype, $depname,
+            $depsense, $depevr 
+        ],
+    )->get_column('pkgid');
+    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
+        {
+            pkgid => 
+                { IN => $deprs->as_query, },
+        },
+    );
+    $c->forward('format_search', $searchspec);
+}
+
+sub byfile : XMLRPCPath('/search/rpm/byfile') {
+    my ( $self, $c, $searchspec, $file) = @_;
+    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
+    $searchspec ||= {};
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    my $filers = $c->forward('file_rs', [ $searchspec, $file ])
+        ->get_column('pkgid');
+    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
+        {
+            $distrs
+                ? { pkgid => { IN => $distrs->get_column('pkgid')->as_query, }, }
+                : (),
+        },
+    );
+    $c->forward('format_search', $searchspec);
+}
+
+sub fuzzy : XMLRPCPath('/search/rpm/fuzzy') {
+    my ($self, $c, $searchspec, $name) = @_;
+    $searchspec ||= {};
+
+    my $deprs = $c->model('Base')->resultset('Deps')->search(
+        { deptype => 'P', depname => { '~*' => $name } }
+    )->get_column('pkgid');
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    $c->stash->{rs} = 
+
+        $c->model('Base')->resultset('Rpms')->search(
+        {
+            -and => [
+                (exists($searchspec->{src})
+                    ? { issrc => $searchspec->{src} ? 1 : 0 }
+                    : ()),
+                { -or => [
+                    { name => 
+                        { '~*' => $name, },
+                    },
+#                    { pkgid =>
+#                        { IN => $deprs->as_query, },
+#                    },
+                     ]
+                },
+                $distrs
+                    ? { pkgid => { IN => $distrs->get_column('pkgid')->as_query, }, }
+                    : (),
+            ]     
+        },
+    );
+    
+    $c->forward('format_search', $searchspec);
+}
+
+sub quick : XMLRPCPath('/search/rpm/quick') {
+    my ($self, $c, $searchspec, @keywords) = @_;
+    $searchspec ||= {};
+    my $tsquery = join(' & ', map { $_ =~ s/ /\\ /g; $_ } @keywords);
+    
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+
+    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
+            {
+                -or => [
+#                    { -nest => \[
+#                        "to_tsvector('english', description) @@ to_tsquery(?)",
+#                        [ plain_text => $tsquery],
+#                    ], },
+                    {
+                    name => { '~*' => [ @keywords ] },
+                    },
+                ],
+            (exists($searchspec->{src})
+                ? (issrc => $searchspec->{src} ? 1 : 0)
+                : ()),
+            ($distrs 
+                ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
+                : ()),
+        },
+    );
+    $c->forward('format_search', $searchspec);
+}
+
+sub description : XMLRPCPath('/search/rpm/description') {
+    my ($self, $c, $searchspec, @keywords) = @_;
+    $searchspec ||= {};
+    my $tsquery = join(' & ', map { $_ =~ s/ /\\ /g; $_ } @keywords);
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search(
+        {
+            -nest => \[
+                    "to_tsvector('english', description) @@ to_tsquery(?)",
+                    [ plain_text => $tsquery],
+                ],
+                (exists($searchspec->{src})
+                    ? (issrc => $searchspec->{src} ? 1 : 0)
+                    : ()),
+                ($distrs 
+                    ? (pkgid => { IN => $distrs->get_column('pkgid')->as_query, },)
+                    : ()),
+        },
+        {
+            select => [ 
+                "ts_rank_cd(to_tsvector('english', description),to_tsquery(?)) as rank",
+                'pkgid'
+            ],
+            bind => [ $tsquery ], 
+            order_by => [ 'rank desc', 'name', 'evr using >>', 'issrc' ],
+        },
+    )->as_subselect_rs;
+    $c->forward('format_search', $searchspec);
+}
+
+sub file_search : XMLRPCPath('/search/file/byname') {
+    my ( $self, $c, $searchspec, $file) = @_;
+    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
+    $searchspec ||= {};
+
+    $c->stash->{rs} = $c->forward('file_rs', [ $searchspec, $file ]);
+    
+    my @col = qw(dirname basename md5 size pkgid count);
+    $c->stash->{column} = [ @col, qw(has_content perm user group) ];
+    
+    $c->forward('format_search', $searchspec);
+}
+
+sub dep_search : XMLRPCPath('/search/dep/match') {
+    my ($self, $c, $searchspec, $deptype, $depname, $depsense, $depevr) = @_;
+
+    my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]);
+    $c->stash->{rs} = $c->forward(
+        'deps_rs', [ 
+            $searchspec, $deptype, $depname,
+            $depsense, $depevr 
+        ],
     );
 
