source: trunk/t/35_supersearch_two_searches.t @ 469

Last change on this file since 469 was 469, checked in by kake, 17 years ago

Added option of using Plucene for searching.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1use strict;
2use CGI::Wiki::Setup::SQLite;
3use Config::Tiny;
4use OpenGuides::SuperSearch;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    plan skip_all => "DBD::SQLite not installed";
10} else {
11    plan tests => 2;
12
13    # Clear out the database from any previous runs.
14    unlink "t/node.db";
15    unlink <t/indexes/*>;
16
17    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
18    my $config = Config::Tiny->new;
19    $config->{_} = {
20                     dbtype             => "sqlite",
21                     dbname             => "t/node.db",
22                     indexing_directory => "t/indexes",
23                     script_name        => "wiki.cgi",
24                     script_url         => "http://example.com/",
25                     site_name          => "Test Site",
26                     template_path      => "./templates",
27                   };
28
29    # Plucene is the recommended searcher now.
30    eval { require CGI::Wiki::Search::Plucene; };
31    unless ( $@ ) {
32        $config->{_}{use_plucene} = 1;
33    }
34
35    my $search = OpenGuides::SuperSearch->new( config => $config );
36
37    # Write some data.
38    my $wiki = $search->{wiki};
39    $wiki->write_node( "Wandsworth Common", "A common.", undef,
40                       { category => "Parks" } )
41        or die "Can't write node";
42    $wiki->write_node( "Hammersmith", "A page about Hammersmith." )
43        or die "Can't write node";
44
45    my (%tt_vars, @results);
46    %tt_vars = $search->run(
47                             return_tt_vars => 1,
48                             vars           => { search => "parks" },
49                           );
50    @results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
51    is_deeply( \@results, [ "Wandsworth_Common" ],
52               "first search returns expected results" );
53    %tt_vars = $search->run(
54                             return_tt_vars => 1,
55                             vars           => { search => "hammersmith" },
56                           );
57    @results = sort map { $_->{name} } @{ $tt_vars{results} || [] };
58    is_deeply( \@results, [ "Hammersmith" ],
59               "so does second" );
60
61}
Note: See TracBrowser for help on using the repository browser.