source: trunk/t/32_supersearch_simple_metadata.t @ 587

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

Encapsulate config data in OpenGuides::Config.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1use strict;
2use CGI::Wiki::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides::SuperSearch;
5use Test::More tests => 10;
6
7eval { require DBD::SQLite; };
8my $have_sqlite = $@ ? 0 : 1;
9
10SKIP: {
11    skip "DBD::SQLite not installed - no database to test with", 10
12      unless $have_sqlite;
13
14    # Clear out the database from any previous runs.
15    unlink "t/node.db";
16    unlink <t/indexes/*>;
17
18    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
19    my $config = OpenGuides::Config->new(
20           vars => {
21                     dbtype             => "sqlite",
22                     dbname             => "t/node.db",
23                     indexing_directory => "t/indexes",
24                     script_name        => "wiki.cgi",
25                     script_url         => "http://example.com/",
26                     site_name          => "Test Site",
27                     template_path      => "./templates",
28                   }
29    );
30
31    # Plucene is the recommended searcher now.
32    eval { require CGI::Wiki::Search::Plucene; };
33    unless ( $@ ) {
34        $config->use_plucene( 1 );
35    }
36
37    my $search = OpenGuides::SuperSearch->new( config => $config );
38
39    # Add some data.  We write it twice to avoid hitting the redirect.
40    my $wiki = $search->{wiki}; # white boxiness
41    $wiki->write_node( "Calthorpe Arms", "Serves beer.", undef,
42                       { category => "Pubs", locale => "Holborn" } );
43    $wiki->write_node( "Penderel's Oak", "Serves beer.", undef,
44                       { category => "Pubs", locale => "Holborn" } );
45    $wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef,
46                       { category => ["Museums", "Major Attractions"]
47                       , locale => ["Holborn", "Bloomsbury"] } );
48
49    # Check that a search on its category works.
50    my %tt_vars = $search->run(
51                                return_tt_vars => 1,
52                                vars           => { search => "Pubs" },
53                              );
54    my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
55    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
56               "simple search looks in category" );
57
58    %tt_vars = $search->run(
59                             return_tt_vars => 1,
60                             vars           => { search => "pubs" },
61                           );
62    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
63    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
64               "...and is case-insensitive" );
65
66    # Check that a search on its locale works.
67    %tt_vars = $search->run(
68                             return_tt_vars => 1,
69                             vars           => { search => "Holborn" },
70                           );
71    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
72    is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
73               "simple search looks in locale" );
74
75    %tt_vars = $search->run(
76                             return_tt_vars => 1,
77                             vars           => { search => "holborn" },
78                           );
79    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
80    is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
81               "...and is case-insensitive" );
82
83    # Test AND search in various combinations.
84    %tt_vars = $search->run(
85                             return_tt_vars => 1,
86                             vars           => { search => "Holborn Pubs" },
87                           );
88    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
89    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
90               "AND search works between category and locale" );
91
92    %tt_vars = $search->run(
93                             return_tt_vars => 1,
94                             vars         => { search => "Holborn Penderel" },
95                           );
96    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
97    is_deeply( \@found, [ "Penderel's Oak" ],
98               "AND search works between title and locale" );
99
100    %tt_vars = $search->run(
101                             return_tt_vars => 1,
102                             vars           => { search => "Pubs Penderel" },
103                           );
104    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
105    is_deeply( \@found, [ "Penderel's Oak" ],
106               "AND search works between title and category" );
107
108    %tt_vars = $search->run(
109                             return_tt_vars => 1,
110                             vars           => { search => "Holborn beer" },
111                           );
112    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
113    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
114               "...and between body and locale" );
115
116    %tt_vars = $search->run(
117                             return_tt_vars => 1,
118                             vars           => { search => "Pubs beer" },
119                           );
120    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
121    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
122               "...and between body and category" );
123
124    %tt_vars = $search->run(
125                             return_tt_vars => 1,
126                             vars           => { search => '"major attractions"' },
127                           );
128    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
129    is_deeply( \@found, [ "British Museum", ],
130               "Multi word category name" );
131}
Note: See TracBrowser for help on using the repository browser.