Changeset 552
- Timestamp:
- 11/17/04 01:49:15 (4 years ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
Build.PL (modified) (1 diff)
-
Changes (modified) (1 diff)
-
t/22_rss_modwiki.t (modified) (1 diff)
-
t/36_supersearch_order.t (modified) (1 diff)
-
t/38_supersearch_params.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Build.PL
r540 r552 42 42 variable => "custom_lib_path", 43 43 }, 44 { question => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this )",44 { question => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)", 45 45 variable => "use_plucene", 46 default => " n",46 default => "y", 47 47 type => "y_n" 48 48 }, -
trunk/Changes
r551 r552 5 5 Fixed a couple of minor bugs in the search - note that node.tt 6 6 and supersearch.tt have changed. 7 Change the default indexer for new installs to Plucene. 8 Only run certain search-related tests if Plucene is installed. 7 9 8 10 0.43 21 October 2004 -
trunk/t/22_rss_modwiki.t
r550 r552 10 10 if ( $@ ) { 11 11 plan skip_all => "DBD::SQLite not installed"; 12 } else { 13 plan tests => 7; 12 exit 0; 13 } 14 14 15 # Clear out the database from any previous runs. 16 unlink "t/node.db"; 17 unlink <t/indexes/*>; 15 eval { require CGI::Wiki::Search::Plucene; }; 16 if ( $@ ) { 17 plan skip_all => "Plucene not installed"; 18 exit 0; 19 } 18 20 19 CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 20 my $config = Config::Tiny->new; 21 $config->{_} = { 22 dbtype => "sqlite", 23 dbname => "t/node.db", 24 indexing_directory => "t/indexes", 25 script_name => "wiki.cgi", 26 script_url => "http://example.com/", 27 site_name => "Test Site", 28 template_path => "./templates", 29 home_name => "Home", 30 }; 21 plan tests => 7; 31 22 32 # Plucene is the recommended searcher now. 33 eval { require CGI::Wiki::Search::Plucene; }; 34 unless ( $@ ) { 35 $config->{_}{use_plucene} = 1; 36 } 23 # Clear out the database from any previous runs. 24 unlink "t/node.db"; 25 unlink <t/indexes/*>; 37 26 38 # Basic sanity check first. 39 my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 27 CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 28 my $config = Config::Tiny->new; 29 $config->{_} = { 30 dbtype => "sqlite", 31 dbname => "t/node.db", 32 indexing_directory => "t/indexes", 33 script_name => "wiki.cgi", 34 script_url => "http://example.com/", 35 site_name => "Test Site", 36 template_path => "./templates", 37 home_name => "Home", 38 use_plucene => 1 39 }; 40 40 41 my $rdf_writer = OpenGuides::RDF->new( wiki => $wiki, 42 config => $config );41 # Basic sanity check first. 42 my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 43 43 44 my $rss = eval { $rdf_writer->make_recentchanges_rss; }; 45 is( $@, "", "->make_recentchanges_rss doesn't croak");44 my $rdf_writer = OpenGuides::RDF->new( wiki => $wiki, 45 config => $config ); 46 46 47 # Now write some data, first a minor edit then a non-minor one. 48 my $guide = OpenGuides->new( config => $config ); 47 my $rss = eval { $rdf_writer->make_recentchanges_rss; }; 48 is( $@, "", "->make_recentchanges_rss doesn't croak" ); 49 50 # Now write some data, first a minor edit then a non-minor one. 51 my $guide = OpenGuides->new( config => $config ); 49 52 50 # Set up CGI parameters ready for a node write.51 # Most of these are in here to avoid uninitialised value warnings.52 my $q = CGI->new;53 $q->param( -name => "content", -value => "foo" );54 $q->param( -name => "categories", -value => "" );55 $q->param( -name => "locales", -value => "" );56 $q->param( -name => "phone", -value => "" );57 $q->param( -name => "fax", -value => "" );58 $q->param( -name => "website", -value => "" );59 $q->param( -name => "hours_text", -value => "" );60 $q->param( -name => "address", -value => "" );61 $q->param( -name => "postcode", -value => "" );62 $q->param( -name => "map_link", -value => "" );63 $q->param( -name => "os_x", -value => "" );64 $q->param( -name => "os_y", -value => "" );65 $q->param( -name => "username", -value => "bob" );66 $q->param( -name => "comment", -value => "foo" );67 $q->param( -name => "edit_type", -value => "Minor tidying" );68 $ENV{REMOTE_ADDR} = "127.0.0.1";53 # Set up CGI parameters ready for a node write. 54 # Most of these are in here to avoid uninitialised value warnings. 55 my $q = CGI->new; 56 $q->param( -name => "content", -value => "foo" ); 57 $q->param( -name => "categories", -value => "" ); 58 $q->param( -name => "locales", -value => "" ); 59 $q->param( -name => "phone", -value => "" ); 60 $q->param( -name => "fax", -value => "" ); 61 $q->param( -name => "website", -value => "" ); 62 $q->param( -name => "hours_text", -value => "" ); 63 $q->param( -name => "address", -value => "" ); 64 $q->param( -name => "postcode", -value => "" ); 65 $q->param( -name => "map_link", -value => "" ); 66 $q->param( -name => "os_x", -value => "" ); 67 $q->param( -name => "os_y", -value => "" ); 68 $q->param( -name => "username", -value => "bob" ); 69 $q->param( -name => "comment", -value => "foo" ); 70 $q->param( -name => "edit_type", -value => "Minor tidying" ); 71 $ENV{REMOTE_ADDR} = "127.0.0.1"; 69 72 70 my $output = $guide->commit_node(71 return_output => 1,72 id => "Wombats",73 cgi_obj => $q,74 );73 my $output = $guide->commit_node( 74 return_output => 1, 75 id => "Wombats", 76 cgi_obj => $q, 77 ); 75 78 76 $q->param( -name => "edit_type", -value => "Normal edit" );77 $output = $guide->commit_node(78 return_output => 1,79 id => "Badgers",80 cgi_obj => $q,81 );79 $q->param( -name => "edit_type", -value => "Normal edit" ); 80 $output = $guide->commit_node( 81 return_output => 1, 82 id => "Badgers", 83 cgi_obj => $q, 84 ); 82 85 83 $q->param( -name => "username", -value => "Kake" );84 $output = $guide->commit_node(85 return_output => 1,86 id => "Wombles",87 cgi_obj => $q,88 );86 $q->param( -name => "username", -value => "Kake" ); 87 $output = $guide->commit_node( 88 return_output => 1, 89 id => "Wombles", 90 cgi_obj => $q, 91 ); 89 92 90 # Check that the writes went in.91 ok( $wiki->node_exists( "Wombats" ), "Wombats written" );92 ok( $wiki->node_exists( "Badgers" ), "Badgers written" );93 ok( $wiki->node_exists( "Wombles" ), "Wombles written" );93 # Check that the writes went in. 94 ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); 95 ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); 96 ok( $wiki->node_exists( "Wombles" ), "Wombles written" ); 94 97 95 # Check that the minor edits can be filtered out.96 $output = $guide->display_rss(97 items => 5,98 username => "bob",99 ignore_minor_edits => 1,100 return_output => 1,101 );102 unlike( $output, qr/Wombats/, "minor edits filtered out when required" );103 like( $output, qr/Badgers/, "but normal edits still in" );98 # Check that the minor edits can be filtered out. 99 $output = $guide->display_rss( 100 items => 5, 101 username => "bob", 102 ignore_minor_edits => 1, 103 return_output => 1, 104 ); 105 unlike( $output, qr/Wombats/, "minor edits filtered out when required" ); 106 like( $output, qr/Badgers/, "but normal edits still in" ); 104 107 105 # Check that the username parameter is taken notice of. 106 unlike( $output, qr/Wombles/, "username parameter taken note of" ); 107 } 108 # Check that the username parameter is taken notice of. 109 unlike( $output, qr/Wombles/, "username parameter taken note of" ); -
trunk/t/36_supersearch_order.t
r543 r552 8 8 if ( $@ ) { 9 9 plan skip_all => "DBD::SQLite not installed"; 10 } else { 11 plan tests => 9; 10 exit 0; 11 } 12 12 13 # Clear out the database from any previous runs. 14 unlink "t/node.db"; 15 unlink <t/indexes/*>; 13 eval { require CGI::Wiki::Search::Plucene; }; 14 if ( $@ ) { 15 plan skip_all => "Plucene not installed"; 16 exit 0; 17 } 16 18 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 }; 19 plan tests => 9; 28 20 29 # Plucene is the recommended searcher now. 30 eval { require CGI::Wiki::Search::Plucene; }; 31 unless ( $@ ) { 32 $config->{_}{use_plucene} = 1; 33 } 21 # Clear out the database from any previous runs. 22 unlink "t/node.db"; 23 unlink <t/indexes/*>; 34 24 35 my $search = OpenGuides::SuperSearch->new( config => $config ); 36 isa_ok( $search, "OpenGuides::SuperSearch" ); 25 CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 26 my $config = Config::Tiny->new; 27 $config->{_} = { 28 dbtype => "sqlite", 29 dbname => "t/node.db", 30 indexing_directory => "t/indexes", 31 script_name => "wiki.cgi", 32 script_url => "http://example.com/", 33 site_name => "Test Site", 34 template_path => "./templates", 35 use_plucene => 1 36 }; 37 37 38 # Write some data. 39 my $wiki = $search->{wiki}; 40 $wiki->write_node( "Parks", "A page about parks." ) 41 or die "Can't write node"; 42 $wiki->write_node( "Wandsworth Common", "A common.", undef, 43 { category => "Parks" } ) 44 or die "Can't write node"; 45 $wiki->write_node( "Kake", "I like walking in parks." ) 46 or die "Can't write node"; 38 my $search = OpenGuides::SuperSearch->new( config => $config ); 39 isa_ok( $search, "OpenGuides::SuperSearch" ); 47 40 48 my %tt_vars = $search->run( 49 return_tt_vars => 1, 50 vars => { search => "parks" }, 51 ); 52 foreach my $result ( @{ $tt_vars{results} || [] } ) { 53 print "# $result->{name} scores $result->{score}\n"; 54 } 55 my %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 56 ok( $scores{Kake} < $scores{'Wandsworth Common'}, 57 "content match scores less than category match" ); 58 ok( $scores{'Wandsworth Common'} < $scores{Parks}, 59 "title match scores more than category match" ); 41 # Write some data. 42 my $wiki = $search->{wiki}; 43 $wiki->write_node( "Parks", "A page about parks." ) 44 or die "Can't write node"; 45 $wiki->write_node( "Wandsworth Common", "A common.", undef, 46 { category => "Parks" } ) 47 or die "Can't write node"; 48 $wiki->write_node( "Kake", "I like walking in parks." ) 49 or die "Can't write node"; 60 50 61 # Now test locales. 62 $wiki->write_node( "Hammersmith", "A page about Hammersmith." ) 63 or die "Can't write node"; 64 $wiki->write_node( "The Gate", "A restaurant.", undef, 65 { locale => "Hammersmith" } ) 66 or die "Can't write node"; 67 $wiki->write_node( "Kake Pugh", "I live in Hammersmith." ) 68 or die "Can't write node"; 51 my %tt_vars = $search->run( 52 return_tt_vars => 1, 53 vars => { search => "parks" }, 54 ); 55 foreach my $result ( @{ $tt_vars{results} || [] } ) { 56 print "# $result->{name} scores $result->{score}\n"; 57 } 58 my %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 59 ok( $scores{Kake} < $scores{'Wandsworth Common'}, 60 "content match scores less than category match" ); 61 ok( $scores{'Wandsworth Common'} < $scores{Parks}, 62 "title match scores more than category match" ); 69 63 70 %tt_vars = $search->run( 71 return_tt_vars => 1, 72 vars => { search => "hammersmith" }, 73 ); 74 foreach my $result ( @{ $tt_vars{results} || [] } ) { 75 print "# $result->{name} scores $result->{score}\n"; 76 } 77 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 78 ok( $scores{'Kake Pugh'} < $scores{'The Gate'}, 79 "content match scores less than locale match" ); 80 ok( $scores{'The Gate'} < $scores{Hammersmith}, 81 "locale match scores less than title match" ); 64 # Now test locales. 65 $wiki->write_node( "Hammersmith", "A page about Hammersmith." ) 66 or die "Can't write node"; 67 $wiki->write_node( "The Gate", "A restaurant.", undef, 68 { locale => "Hammersmith" } ) 69 or die "Can't write node"; 70 $wiki->write_node( "Kake Pugh", "I live in Hammersmith." ) 71 or die "Can't write node"; 82 72 83 # Check that two words in the title beats one in the title and 84 # one in the content. 85 $wiki->write_node( "Putney Tandoori", "Indian food" ) 86 or die "Couldn't write node"; 87 $wiki->write_node( "Putney", "There is a tandoori restaurant here" ) 88 or die "Couldn't write node"; 73 %tt_vars = $search->run( 74 return_tt_vars => 1, 75 vars => { search => "hammersmith" }, 76 ); 77 foreach my $result ( @{ $tt_vars{results} || [] } ) { 78 print "# $result->{name} scores $result->{score}\n"; 79 } 80 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 81 ok( $scores{'Kake Pugh'} < $scores{'The Gate'}, 82 "content match scores less than locale match" ); 83 ok( $scores{'The Gate'} < $scores{Hammersmith}, 84 "locale match scores less than title match" ); 89 85 90 %tt_vars = $search->run( 91 return_tt_vars => 1, 92 vars => { search => "putney tandoori" }, 93 ); 94 foreach my $result ( @{ $tt_vars{results} || [] } ) { 95 print "# $result->{name} scores $result->{score}\n"; 96 } 97 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 98 ok( $scores{Putney} < $scores{'Putney Tandoori'}, 99 "two words in title beats one in title and one in content" ); 86 # Check that two words in the title beats one in the title and 87 # one in the content. 88 $wiki->write_node( "Putney Tandoori", "Indian food" ) 89 or die "Couldn't write node"; 90 $wiki->write_node( "Putney", "There is a tandoori restaurant here" ) 91 or die "Couldn't write node"; 100 92 101 SKIP: { 102 skip "Word proximity not yet taken into account", 1; 103 # Check that in an AND match words closer together get higher priority. 104 $wiki->write_node( "Spitalfields Market", 105 "Mango juice from the Indian stall" ) 106 or die "Can't write node"; 107 $wiki->write_node( "Borough Market", "dried mango and real apple juice" ) 108 or die "Can't write node"; 93 %tt_vars = $search->run( 94 return_tt_vars => 1, 95 vars => { search => "putney tandoori" }, 96 ); 97 foreach my $result ( @{ $tt_vars{results} || [] } ) { 98 print "# $result->{name} scores $result->{score}\n"; 99 } 100 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 101 ok( $scores{Putney} < $scores{'Putney Tandoori'}, 102 "two words in title beats one in title and one in content" ); 109 103 110 %tt_vars = $search->run( 111 return_tt_vars => 1, 112 vars => { search => "mango juice" }, 113 ); 114 foreach my $result ( @{ $tt_vars{results} || [] } ) { 115 print "# $result->{name} scores $result->{score}\n"; 116 } 117 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 118 ok( $scores{'Borough Market'} < $scores{'Spitalfields Market'}, 119 "words closer together gives higher score" ); 120 } # end of SKIP 104 SKIP: { 105 skip "Word proximity not yet taken into account", 1; 106 # Check that in an AND match words closer together get higher priority. 107 $wiki->write_node( "Spitalfields Market", 108 "Mango juice from the Indian stall" ) 109 or die "Can't write node"; 110 $wiki->write_node( "Borough Market", "dried mango and real apple juice" ) 111 or die "Can't write node"; 121 112 122 # Check that the number of occurrences of the search term is significant. 113 %tt_vars = $search->run( 114 return_tt_vars => 1, 115 vars => { search => "mango juice" }, 116 ); 117 foreach my $result ( @{ $tt_vars{results} || [] } ) { 118 print "# $result->{name} scores $result->{score}\n"; 119 } 120 %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; 121 ok( $scores{'Borough Market'} < $scores{'Spitalfields Market'}, 122 "words closer together gives higher score" ); 123 } # end of SKIP 123 124 124 $wiki->write_node( "Pub Crawls", "The basic premise of the pub crawl is to visit a succession of pubs, rather than spending the entire evening or day in a single establishment. London offers an excellent choice of themes for your pub crawl.", undef, { category => "Pubs" } ) or die "Can't write node"; 125 $wiki->write_node( "The Pub", "A pub.", undef, { category => "Pubs" } ) or die "Can't write node"; 125 # Check that the number of occurrences of the search term is significant. 126 126 127 %tt_vars = $search->run( 128 return_tt_vars => 1, 129 vars => { search => "pub" } 130 ); 131 foreach my $result ( @{ $tt_vars{results} || [] } ) { 132 print "# $result->{name} scores $result->{score}\n"; 133 } 134 is( $tt_vars{results}[0]{name}, "Pub Crawls", 135 "node with two mentions of search term comes top" ); 136 ok( $tt_vars{results}[0]{score} > $tt_vars{results}[1]{score}, 137 "...with a score strictly greater than node with one mention" ); 127 $wiki->write_node( "Pub Crawls", "The basic premise of the pub crawl is to visit a succession of pubs, rather than spending the entire evening or day in a single establishment. London offers an excellent choice of themes for your pub crawl.", undef, { category => "Pubs" } ) or die "Can't write node"; 128 $wiki->write_node( "The Pub", "A pub.", undef, { category => "Pubs" } ) or die "Can't write node"; 138 129 130 %tt_vars = $search->run( 131 return_tt_vars => 1, 132 vars => { search => "pub" } 133 ); 134 foreach my $result ( @{ $tt_vars{results} || [] } ) { 135 print "# $result->{name} scores $result->{score}\n"; 139 136 } 137 is( $tt_vars{results}[0]{name}, "Pub Crawls", 138 "node with two mentions of search term comes top" ); 139 ok( $tt_vars{results}[0]{score} > $tt_vars{results}[1]{score}, 140 "...with a score strictly greater than node with one mention" ); -
trunk/t/38_supersearch_params.t
r545 r552 9 9 if ( $@ ) { 10 10 plan skip_all => "DBD::SQLite not installed"; 11 } else { 12 plan tests => 4; 11 exit 0; 12 } 13 13 14 # Clear out the database from any previous runs. 15 unlink "t/node.db"; 16 unlink <t/indexes/*>; 14 eval { require CGI::Wiki::Search::Plucene; }; 15 if ( $@ ) { 16 plan skip_all => "Plucene not installed"; 17 exit 0; 18 } 17 19 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 }; 20 plan tests => 4; 29 21 30 # Plucene is the recommended searcher now. 31 eval { require CGI::Wiki::Search::Plucene; }; 32 unless ( $@ ) { 33 $config->{_}{use_plucene} = 1; 34 } 22 # Clear out the database from any previous runs. 23 unlink "t/node.db"; 24 unlink <t/indexes/*>; 35 25 36 # Check we get the right distance when we supply OS co-ords. 37 my $search = OpenGuides::SuperSearch->new( config => $config ); 38 isa_ok( $search, "OpenGuides::SuperSearch" ); 26 CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 27 my $config = Config::Tiny->new; 28 $config->{_} = { 29 dbtype => "sqlite", 30 dbname => "t/node.db", 31 indexing_directory => "t/indexes", 32 script_name => "wiki.cgi", 33 script_url => "http://example.com/", 34 site_name => "Test Site", 35 template_path => "./templates", 36 use_plucene => 1 37 }; 39 38 40 my $q = CGI->new; 41 $q->param( -name => "os_x", -value => 500000 ); 42 $q->param( -name => "os_y", -value => 200000 ); 43 $q->param( -name => "os_dist", -value => 500 ); 44 $q->param( -name => "latlong_dist", -value => 600 ); 45 my %vars = $q->Vars(); 39 # Check we get the right distance when we supply OS co-ords. 40 my $search = OpenGuides::SuperSearch->new( config => $config ); 41 isa_ok( $search, "OpenGuides::SuperSearch" ); 46 42 47 $search->run( vars => \%vars, return_output => 1 ); 48 is( $search->{distance_in_metres}, 500, 49 "os_dist picked up in pref. to latlong_dist when OS co-ords given" ); 43 my $q = CGI->new; 44 $q->param( -name => "os_x", -value => 500000 ); 45 $q->param( -name => "os_y", -value => 200000 ); 46 $q->param( -name => "os_dist", -value => 500 ); 47 $q->param( -name => "latlong_dist", -value => 600 ); 48 my %vars = $q->Vars(); 50 49 51 # Check we get the right distance when we supply lat/long. 52 $search = OpenGuides::SuperSearch->new( config => $config ); 53 isa_ok( $search, "OpenGuides::SuperSearch" );50 $search->run( vars => \%vars, return_output => 1 ); 51 is( $search->{distance_in_metres}, 500, 52 "os_dist picked up in pref. to latlong_dist when OS co-ords given" ); 54 53 55 $q = CGI->new( "" ); 56 $q->param( -name => "lat", -value => 51 ); 57 $q->param( -name => "long", -value => 1 ); 58 $q->param( -name => "os_dist", -value => 500 ); 59 $q->param( -name => "latlong_dist", -value => 600 ); 60 %vars = $q->Vars(); 54 # Check we get the right distance when we supply lat/long. 55 $search = OpenGuides::SuperSearch->new( config => $config ); 56 isa_ok( $search, "OpenGuides::SuperSearch" ); 61 57 62 $search->run( vars => \%vars, return_output => 1 ); 63 is( $search->{distance_in_metres}, 600, 64 "latlong_dist picked up in pref. to os_dist when lat/long given" ); 65 } 58 $q = CGI->new( "" ); 59 $q->param( -name => "lat", -value => 51 ); 60 $q->param( -name => "long", -value => 1 ); 61 $q->param( -name => "os_dist", -value => 500 ); 62 $q->param( -name => "latlong_dist", -value => 600 ); 63 %vars = $q->Vars(); 64 65 $search->run( vars => \%vars, return_output => 1 ); 66 is( $search->{distance_in_metres}, 600, 67 "latlong_dist picked up in pref. to os_dist when lat/long given" );
