Author: nick Date: 2006-07-06 18:01:05 +0100 (Thu, 06 Jul 2006) New Revision: 818
Added: trunk/t/40_search_as_feed.t Modified: trunk/MANIFEST trunk/lib/OpenGuides/Search.pm Log: Support (+test) searching as a feed
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2006-07-06 16:09:18 UTC (rev 817) +++ trunk/MANIFEST 2006-07-06 17:01:05 UTC (rev 818) @@ -66,6 +66,7 @@ t/21_rdf.t t/22_feed_recent_changes.t t/23_feed_node_all_versions.t +t/24_feed_node_listings.t t/25_write_geo_data.t t/26_geo_data_search_form.t t/27_geo_data_edit_form.t @@ -80,6 +81,7 @@ t/37_search_summaries.t t/38_search_params.t t/39_search_form.t +t/40_search_as_feed.t t/41_deletion.t t/51_display_node.t t/52_display_diffs.t
Modified: trunk/lib/OpenGuides/Search.pm =================================================================== --- trunk/lib/OpenGuides/Search.pm 2006-07-06 16:09:18 UTC (rev 817) +++ trunk/lib/OpenGuides/Search.pm 2006-07-06 17:01:05 UTC (rev 818) @@ -149,6 +149,7 @@ }
my %tt_vars = ( + format => $args{'vars'}->{'format'}, ss_version => $VERSION, ss_info_url => 'http://openguides.org/page/search_help' ); @@ -693,7 +694,7 @@ return $self; }
-# thin wrapper around OpenGuides::Template +# thin wrapper around OpenGuides::Template, or OpenGuides::Feed sub process_template { my ($self, %args) = @_;
@@ -701,12 +702,29 @@ $tt_vars->{not_editable} = 1; $tt_vars->{not_deletable} = 1; return %$tt_vars if $self->{return_tt_vars}; - my $output = OpenGuides::Template->output( + + # Do we want a feed, or TT html? + my $output; + if($tt_vars->{'format'}) { + my $format = $tt_vars->{'format'}; + my @nodes = @{$tt_vars->{'results'}}; + + my $feed = OpenGuides::Feed->new( + wiki => $self->wiki, + config => $self->config, + og_version => $VERSION, + ); + $output = "Content-Type: ".$feed->default_content_type($format)."\n"; + $output .= $feed->build_mini_feed_for_nodes($format,@nodes); + } else { + $output = OpenGuides::Template->output( wiki => $self->wiki, config => $self->config, template => "search.tt", vars => $tt_vars, ); + } + return $output if $self->{return_output};
print $output;
Added: trunk/t/40_search_as_feed.t =================================================================== --- trunk/t/40_search_as_feed.t 2006-07-06 16:09:18 UTC (rev 817) +++ trunk/t/40_search_as_feed.t 2006-07-06 17:01:05 UTC (rev 818) @@ -0,0 +1,61 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed"; +} else { + plan tests => 7; + + # Clear out the database from any previous runs. + unlink "t/node.db"; + unlink <t/indexes/*>; + + Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + my $config = OpenGuides::Test->make_basic_config; + $config->script_name( "wiki.cgi" ); + $config->script_url( "http://example.com/" ); + + # Plucene is the recommended searcher now. + eval { require Wiki::Toolkit::Search::Plucene; }; + if ( $@ ) { $config->use_plucene( 0 ) }; + + my $search = OpenGuides::Search->new( config => $config ); + isa_ok( $search, "OpenGuides::Search" ); + + # Pop some test data in + my $wiki = $search->{wiki}; # white boxiness + $wiki->write_node( "Banana", "banana" ); + $wiki->write_node( "Monkey", "banana brains" ); + $wiki->write_node( "Monkey Brains", "BRANES" ); + $wiki->write_node( "Want Pie Now", "weebl" ); + $wiki->write_node( "Punctuation", "*" ); + $wiki->write_node( "Choice", "Eenie meenie minie mo"); + + # RSS search, should give 2 hits + my $output = $search->run( + return_output => 1, + vars => { search => "banana", format => "rss" }, + ); + + like($output, qr/<rdf:RDF/, "Really was RSS"); + like($output, qr/<items>/, "Really was RSS"); + + my @found = ($output =~ /(<rdf:li)/g); + is( scalar @found, 2, "found right entries in feed" ); + + + # Atom search, should give 1 hit + $output = $search->run( + return_output => 1, + vars => { search => "weebl", format => "atom" }, + ); + like($output, qr/<feed/, "Really was Atom"); + like($output, qr/<entry>/, "Really was Atom"); + + @found = ($output =~ /(<entry>)/g); + is( scalar @found, 1, "found right entries in feed" ); +}