Changeset 55


Ignore:
Timestamp:
12/01/10 01:43:14 (14 years ago)
Author:
nanardon
Message:
  • rework search
Location:
server/trunk/web/lib/Sophie/Controller
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Distrib.pm

    r54 r55  
    5252 
    5353sub struct :XMLRPC { 
    54     my ( $self, $c, $distrib, $release, $arch ) = @_; 
    55  
    56     my $distribution; 
    57     if (ref $distrib) { 
    58         ($distribution, $release, $arch) = ( 
    59             $distrib->{distribution}, 
    60             $distrib->{release}, 
    61             $distrib->{arch}, 
    62         ); 
    63     } else { 
    64         $distribution = $distrib; 
    65     } 
    66  
    67     my $rs = $c->model('Base')->resultset('Distribution') 
    68         ->search(name => $distribution) 
    69         ->search_related('Release', { version => $release }) 
    70         ->search_related('Arch', { arch => $arch }) 
    71         ->search_related('Medias')->search({}, { order_by => 'label' }); 
     54    my ( $self, $c, $distribution, $release, $arch ) = @_; 
     55 
     56    if (!ref $distribution) { 
     57        $distribution = { 
     58            distribution => $distribution, 
     59            release => $release, 
     60            arch => $arch, 
     61        } 
     62    } 
     63 
     64    my $rs = $c->forward('distrib_rs', [ $distribution ]) 
     65        ->search({}, { order_by => 'label' }); 
    7266    $c->stash->{xmlrpc} = [ map {  
    7367        {  
     
    8680                    ? (name => $distrib->{distribution}) 
    8781                    : () 
    88             } 
     82            }, 
    8983        )->search_related('Release', 
    9084            { 
     
    10599                    ? (group_label => $distrib->{media_group}) 
    106100                    : ()), 
    107             } 
     101            }, 
    108102        ); 
    109103} 
     104 
    110105 
    111106sub exists : XMLRPC { 
     
    294289    $c->stash->{dist}{src} = 1; 
    295290    ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag', 
    296         [ $c->stash->{dist}, 'name', $name ]) }; 
     291        [ $c->stash->{dist}, 'name', $name ])->{results} }; 
    297292    $c->go('/404/index') unless ($c->stash->{pkgid}); 
    298293    $c->go('/rpms/rpms', [ $c->stash->{pkgid} ]); 
     
    311306    my ( $self, $c, $pkgid ) = @_; 
    312307    if ($pkgid) { 
    313         $c->go('/rpms/rpms', [ $pkgid ]); 
     308        if (@{ $c->forward('/search/bypkgid', [ $c->stash->{dist}, $pkgid ]) } ) { 
     309            $c->go('/rpms/rpms', [ $pkgid ]); 
     310        } else { 
     311            $c->go('/404/index'); 
     312        } 
    314313    } else { 
    315314        $c->forward('anyrpms', [ $c->stash->{dist} ]); 
     
    337336    my ( $self, $c, $pkgid ) = @_; 
    338337    if ($pkgid) { 
    339         $c->go('/rpms/rpms', [ $pkgid ]); 
     338        if (@{ $c->forward('/search/bypkgid', [ $c->stash->{dist}, $pkgid ]) } ) { 
     339            $c->go('/rpms/rpms', [ $pkgid ]); 
     340        } else { 
     341            $c->go('/404/index'); 
     342        } 
    340343    } else { 
    341344        $c->forward('anyrpms', [ $c->stash->{dist} ]); 
  • server/trunk/web/lib/Sophie/Controller/Search.pm

    r53 r55  
    7272} 
    7373 
     74sub format_search : Private { 
     75    my ( $self, $c, $searchspec ) = @_; 
     76 
     77    my $rs = $c->stash->{rs}->search( 
     78        {}, 
     79        { 
     80            page => $searchspec->{page} || 1, 
     81            rows => $searchspec->{rows} || 10, 
     82        }, 
     83    ); 
     84 
     85    if (!$searchspec->{page}) { 
     86        my $pager = $rs->pager; 
     87        $c->stash->{xmlrpc} = { 
     88                pages => $pager->last_page, 
     89                current_page => $pager->current_page, 
     90                total_entries => $pager->total_entries, 
     91                entries_per_page => $pager->entries_per_page, 
     92        }; 
     93    } 
     94    $c->stash->{xmlrpc}{results} = [ $rs->get_column('pkgid')->all ]; 
     95} 
     96 
     97sub bypkgid : XMLRPCPath('/search/rpm/bypkgid') { 
     98    my ( $self, $c, $searchspec, $pkgid ) = @_; 
     99 
     100    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search( 
     101        { 
     102            -and => [  
     103                (exists($searchspec->{src}) 
     104                    ? { issrc => $searchspec->{src} ? 1 : 0 } 
     105                    : ()), 
     106                { pkgid => $pkgid },  
     107                { pkgid => 
     108                    { IN => $c->forward('distrib_search', [ $searchspec 
     109                        ])->get_column('pkgid')->as_query, },  
     110                }, 
     111            ]      
     112        }, 
     113    ); 
     114 
     115    $c->forward('format_search', $searchspec); 
     116} 
     117 
    74118sub bytag : XMLRPCPath('/search/rpm/bytag') { 
    75119    my ( $self, $c, $searchspec, $tag, $tagvalue ) = @_; 
     
    78122        ->search({ tagname => lc($tag), value => $tagvalue}) 
    79123        ->get_column('pkgid'); 
    80     $c->stash->{xmlrpc} = [ $c->model('Base')->resultset('Rpms')->search( 
     124    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search( 
    81125        { 
    82126            -and => [  
     
    93137            ]      
    94138        }, 
    95         $c->forward('search_param'), 
    96     )->get_column('pkgid')->all ] 
     139    ); 
     140    $c->forward('format_search', $searchspec); 
    97141 
    98142} 
     
    114158        } 
    115159    )->get_column('pkgid'); 
    116     $c->stash->{xmlrpc} = [ $c->model('Base')->resultset('Rpms')->search( 
     160    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search( 
    117161        { 
    118162            -and => [  
     
    129173            ]      
    130174        }, 
    131         $c->forward('search_param'), 
    132     )->get_column('pkgid')->all ] 
     175    ); 
     176    $c->forward('format_search', $searchspec); 
    133177} 
    134178 
     
    145189        }) 
    146190    ->get_column('pkgid'); 
    147     $c->stash->{xmlrpc} = [ $c->model('Base')->resultset('Rpms')->search( 
     191    $c->stash->{rs} = $c->model('Base')->resultset('Rpms')->search( 
    148192        { 
    149193            -and => [  
     
    160204            ]      
    161205        }, 
    162         $c->forward('search_param'), 
    163     )->get_column('pkgid')->all ] 
     206    ); 
     207    $c->forward('format_search', $searchspec); 
    164208} 
    165209 
     
    183227                        { '~*' => $name, }, 
    184228                    }, 
    185                     { pkgid => 
    186                         { IN => $deprs->as_query, }, 
    187                     }, ] 
     229#                    { pkgid => 
     230#                        { IN => $deprs->as_query, }, 
     231#                    }, 
     232                     ] 
    188233                }, 
    189234                { pkgid => 
     
    196241    ); 
    197242     
    198     if ($c->req->xmlrpc->method) { 
    199         $c->stash->{xmlrpc} = [  
    200             $c->stash->{rs}->get_column('pkgid')->all 
    201         ]; 
    202     } 
     243    $c->forward('format_search', $searchspec); 
    203244} 
    204245 
     
    230271        }, 
    231272    ); 
    232     if ($c->req->xmlrpc->method) { 
    233         $c->stash->{xmlrpc} = [  
    234             $c->stash->{rs}->get_column('pkgid')->all 
    235         ]; 
    236     } 
     273    $c->forward('format_search', $searchspec); 
    237274} 
    238275 
     
    265302        }, 
    266303    ); 
    267     if ($c->req->xmlrpc->method) { 
    268         $c->stash->{xmlrpc} = [  
    269             $c->stash->{rs}->get_column('pkgid')->all 
    270         ]; 
    271     } 
     304    $c->forward('format_search', $searchspec); 
    272305} 
    273306 
Note: See TracChangeset for help on using the changeset viewer.