Changeset 1186

Show
Ignore:
Timestamp:
07/30/06 16:27:52
Author:
miyagawa
Message:
  • Unit test for Search::Estraier
  • Implemented searcher.search in Search::Estraier. Refs #62
  • Added test_requires_command in t::TestPlagger?
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Search/Estraier.pm

    r675 r1186  
    1010    $self->SUPER::init(@_); 
    1111 
    12     $self->conf->{url}      ||= "http://localhost:1978/node/Plagger"; 
     12    $self->conf->{url}      ||= "http://localhost:1978/node/plagger"; 
    1313    $self->conf->{username} ||= "admin"; 
    1414    $self->conf->{password} ||= "admin"; 
     
    2727        $self, 
    2828        'publish.entry' => \&entry, 
     29        'searcher.search'  => \&search, 
    2930    ); 
    3031} 
     
    5253} 
    5354 
     55sub search { 
     56    my($self, $context, $args) = @_; 
     57 
     58    my $cond = Search::Estraier::Condition->new; 
     59    $cond->set_phrase( encode_utf8($args->{query}) ); 
     60 
     61    my $nres = $self->{node}->search($cond, 0); 
     62    defined $nres or $context->error("search failed: " . $self->{node}->status); 
     63 
     64    my $feed = Plagger::Feed->new; 
     65    $feed->type('search:Estraier'); 
     66    $feed->title("Search: $args->{query}"); 
     67 
     68    for my $i ( 0 .. $nres->doc_num - 1 ) { 
     69        my $doc = $nres->get_doc($i); 
     70        my $entry = Plagger::Entry->new; 
     71 
     72        $entry->link( $doc->attr('@uri') ); 
     73        $entry->title( decode_utf8($doc->attr('@title')) ); 
     74        $entry->date( $doc->attr('@cdate') )    if $doc->attr('@cdate'); 
     75        $entry->author( decode_utf8($doc->attr('@author')) ) if $doc->attr('@author'); 
     76        $entry->body( decode_utf8($doc->snippet) ); 
     77 
     78        $feed->add_entry($entry); 
     79    } 
     80 
     81 
     82    return $feed; 
     83} 
     84 
    5485sub _u { 
    5586    my $str = shift; 
     
    70101  - module: Search::Estraier 
    71102    config: 
    72       url: http://localhost:1978/node/Plagger 
     103      url: http://localhost:1978/node/plagger 
    73104      username: foobar 
    74105      password: p4ssw0rd 
  • trunk/plagger/t/TestPlagger.pm

    r1173 r1186  
    33use Plagger; 
    44 
    5 our @EXPORT = qw(test_requires test_requires_network run_eval_expected slurp_file file_contains file_doesnt_contain); 
     5our @EXPORT = qw(test_requires test_requires_network test_requires_command 
     6                 run_eval_expected slurp_file file_contains file_doesnt_contain); 
    67 
    78sub test_requires() { 
     
    3132        plan skip_all => "Test requires network which is not available now."; 
    3233    } 
     34} 
     35 
     36sub test_requires_command { 
     37    my $command = $self; 
     38    for my $path (split /:/, $ENV{PATH}) { 
     39        if (-e File::Spec->catfile($path, $command) && -x _) { 
     40            return 1; 
     41        } 
     42    } 
     43    plan skip_all => "Test requires '$command' command but it's not found"; 
    3344} 
    3445