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

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

Search efficiency fixes.

  • 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 Config::Tiny;
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 = Config::Tiny->new;
20    $config->{_} = {
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    # Plucene is the recommended searcher now.
31    eval { require CGI::Wiki::Search::Plucene; };
32    unless ( $@ ) {
33        $config->{_}{use_plucene} = 1;
34    }
35
36    my $search = OpenGuides::SuperSearch->new( config => $config );
37
38    # Add some data.  We write it twice to avoid hitting the redirect.
39    my $wiki = $search->{wiki}; # white boxiness
40    $wiki->write_node( "Calthorpe Arms", "Serves beer.", undef,
41                       { category => "Pubs", locale => "Holborn" } );
42    $wiki->write_node( "Penderel's Oak", "Serves beer.", undef,
43                       { category => "Pubs", locale => "Holborn" } );
44    $wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef,
45                       { category => ["Museums", "Major Attractions"]
46                       , locale => ["Holborn", "Bloomsbury"] } );
47
48    # Check that a search on its category works.
49    my %tt_vars = $search->run(
50                                return_tt_vars => 1,
51                                vars           => { search => "Pubs" },
52                              );
53    my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
54    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
55               "simple search looks in category" );
56
57    %tt_vars = $search->run(
58                             return_tt_vars => 1,
59                             vars           => { search => "pubs" },
60                           );
61    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
62    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
63               "...and is case-insensitive" );
64
65    # Check that a search on its locale works.
66    %tt_vars = $search->run(
67                             return_tt_vars => 1,
68                             vars           => { search => "Holborn" },
69                           );
70    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
71    is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
72               "simple search looks in locale" );
73
74    %tt_vars = $search->run(
75                             return_tt_vars => 1,
76                             vars           => { search => "holborn" },
77                           );
78    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
79    is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
80               "...and is case-insensitive" );
81
82    # Test AND search in various combinations.
83    %tt_vars = $search->run(
84                             return_tt_vars => 1,
85                             vars           => { search => "Holborn Pubs" },
86                           );
87    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
88    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
89               "AND search works between category and locale" );
90
91    %tt_vars = $search->run(
92                             return_tt_vars => 1,
93                             vars         => { search => "Holborn Penderel" },
94                           );
95    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
96    is_deeply( \@found, [ "Penderel's Oak" ],
97               "AND search works between title and locale" );
98
99    %tt_vars = $search->run(
100                             return_tt_vars => 1,
101                             vars           => { search => "Pubs Penderel" },
102                           );
103    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
104    is_deeply( \@found, [ "Penderel's Oak" ],
105               "AND search works between title and category" );
106
107    %tt_vars = $search->run(
108                             return_tt_vars => 1,
109                             vars           => { search => "Holborn beer" },
110                           );
111    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
112    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
113               "...and between body and locale" );
114
115    %tt_vars = $search->run(
116                             return_tt_vars => 1,
117                             vars           => { search => "Pubs beer" },
118                           );
119    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
120    is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
121               "...and between body and category" );
122
123    %tt_vars = $search->run(
124                             return_tt_vars => 1,
125                             vars           => { search => '"major attractions"' },
126                           );
127    @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
128    is_deeply( \@found, [ "British Museum", ],
129               "Multi word category name" );
130}
Note: See TracBrowser for help on using the repository browser.