Changeset 1431 for branches/release-30/lib/MT/App/Search.pm
- Timestamp:
- 02/29/08 08:17:29 (21 months ago)
- Files:
-
- 1 modified
-
branches/release-30/lib/MT/App/Search.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-30/lib/MT/App/Search.pm
r1421 r1431 11 11 12 12 use MT::Util qw( encode_html ); 13 use MT::Entry qw( :constants );14 13 15 14 sub id { 'new_search' } … … 27 26 return { 28 27 'search' => \&process, 29 'author' => \&process,30 28 }; 31 29 } … … 66 64 $app->config->$key() : ($q->param($key) || $app->config->$key()); 67 65 } 66 67 $app->{searchparam}{Type} = $q->param('type') || 'entry'; 68 68 } 69 69 … … 121 121 my $app = shift; 122 122 123 my ( $terms, $args )= $app->search_terms();123 my @arguments = $app->search_terms(); 124 124 return $app->error($app->errstr) if $app->errstr; 125 125 126 126 my $count = 0; 127 127 my $iter; 128 if ( $terms && @$terms ) {129 ( $count, $iter ) = $app->execute( $terms, $args );128 if ( @arguments ) { 129 ( $count, $iter ) = $app->execute( @arguments ); 130 130 return $app->error($app->errstr) unless $iter; 131 131 … … 147 147 my ( $terms, $args ) = @_; 148 148 149 my $class = $app->model( $app->mode eq 'search' ? 'entry' : $app->mode ); 149 my $class = $app->model( $app->{searchparam}{Type} ) 150 or return $app->errtrans('Unsupported type: [_1]', $app->{searchparam}{Type}); 150 151 my $count = $app->count( $class, $terms, $args ); 151 152 #TODO: cache! … … 167 168 $limit = $max if !$limit || ( $limit - $offset > $max ); 168 169 169 my $type = $q->param('type'); 170 my $entry_type = $app->mode eq 'search' 171 ? 1 172 : $type 173 ? ( 'entry' eq lc($type) || 'page' eq lc($type) 174 ? 1 175 : 0 ) 176 : 0; 177 178 my $def_terms = { 179 $entry_type ? ( status => MT::Entry::RELEASE() ) : (), 180 $type ? ( class => $type ) : (), 181 exists( $app->{searchparam}{IncludeBlogs} ) 182 ? ( blog_id => [ keys %{ $app->{searchparam}{IncludeBlogs} } ] ) 183 : (), 184 }; 170 my $params = $app->registry( $app->{searchparam}{Type} ); 171 my %def_terms = exists( $params->{terms} ) 172 ? %{ $params->{terms} } 173 : (); 174 delete $def_terms{'plugin'}; #FIXME: why is this in here? 175 176 if ( exists $app->{searchparam}{IncludeBlogs} ) { 177 $def_terms{blog_id} = [ keys %{ $app->{searchparam}{IncludeBlogs} } ]; 178 } 179 185 180 my @terms; 186 push @terms, $def_terms if %$def_terms; 187 188 my $columns = $app->mode eq 'search' 189 ? [ [ qw( title keywords text text_more ) ] ] 190 : $app->registry( $app->mode, 'columns' ); 191 $columns = $columns->[0]; # FIXME: Why? 192 return $app->errtrans('No columns to search for was specified for [_1]', $app->mode) 181 push @terms, \%def_terms if %def_terms; 182 183 my $columns = $params->{columns}; 184 my $sort = $params->{'sort'}; 185 if ( $sort !~ /\w+\!$/ && exists($app->{searchparam}{Sort}) ) { 186 $sort = $app->{searchparam}{Sort}; 187 } 188 189 return $app->errtrans('No column was specified to search for [_1].', $app->{searchparam}{Type}) 193 190 unless $columns && @$columns; 191 194 192 my $number = scalar @$columns; 195 193 my @and; … … 208 206 'sort' => [ 209 207 { desc => 'descend' eq $app->{searchparam}{ResultDisplay} ? 'DESC' : 'ASC', 210 column => $ entry_type ? 'authored_on' : 'created_on'}208 column => $sort } 211 209 ] 212 210 ); … … 296 294 $ctx->stash('results', $iter); 297 295 $ctx->stash('count', $count); 298 $ctx->stash('stash_key', $app->mode) 299 if 'search' ne $app->mode; 296 $ctx->stash('stash_key', $app->{searchparam}{Type} ); 300 297 $ctx->stash('include_blogs', 301 298 join ',', keys %{ $app->{searchparam}{IncludeBlogs} }); … … 313 310 my $app = shift; 314 311 my ( $tmpl ) = @_; 315 $tmpl 312 $tmpl; 316 313 } 317 314 … … 322 319 my $tmpl = $app->load_search_tmpl( $count, $iter ); 323 320 $tmpl = $app->pre_render( $tmpl ); 324 325 321 $tmpl; 326 322 }
