root/trunk/plagger/lib/Plagger/Plugin/Search/Estraier.pm

Revision 675 (checked in by miyagawa, 14 years ago)

don't set cdate if entry date is empty

Line 
1 package Plagger::Plugin::Search::Estraier;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Encode;
6 use Search::Estraier;
7
8 sub init {
9     my $self = shift;
10     $self->SUPER::init(@_);
11
12     $self->conf->{url}      ||= "http://localhost:1978/node/Plagger";
13     $self->conf->{username} ||= "admin";
14     $self->conf->{password} ||= "admin";
15     $self->conf->{timeout}  ||= 30;
16
17     $self->{node} = Search::Estraier::Node->new(
18         url => $self->conf->{url},
19     );
20     $self->{node}->set_auth($self->conf->{username}, $self->conf->{password});
21     $self->{node}->set_timeout($self->conf->{timeout});
22 }
23
24 sub register {
25     my($self, $context) = @_;
26     $context->register_hook(
27         $self,
28         'publish.entry' => \&entry,
29     );
30 }
31
32 sub entry {
33     my($self, $context, $args) = @_;
34
35     return unless $args->{entry}->permalink;
36
37     my $id  = $self->{node}->uri_to_id($args->{entry}->permalink);
38     $context->log(info => "Going to index entry " . $args->{entry}->permalink . ($id ? " with id=$id" : ""));
39
40     my $doc = Search::Estraier::Document->new;
41     $doc->add_attr('@uri' => $args->{entry}->permalink);
42     $doc->add_attr('@title' => _u($args->{entry}->title));
43     $doc->add_attr('@cdate' => $args->{entry}->date->format('W3CDTF')) if $args->{entry}->date;
44     $doc->add_attr('@author' => _u($args->{entry}->author)) if $args->{entry}->author;
45
46     $doc->add_text(_u($args->{entry}->body_text));
47     $doc->add_hidden_text(_u($args->{entry}->title));
48
49     $doc->add_attr('@id' => $id) if $id; # update mode
50
51     $self->{node}->put_doc($doc) or $context->error("Put failure: " . $self->{node}->status);
52 }
53
54 sub _u {
55     my $str = shift;
56     Encode::_utf8_off($str);
57     $str;
58 }
59
60 1;
61
62 __END__
63
64 =head1 NAME
65
66 Plagger::Plugin::Search::Estraier - Search entries using Hyper Estraier P2P
67
68 =head1 SYNOPSIS
69
70   - module: Search::Estraier
71     config:
72       url: http://localhost:1978/node/Plagger
73       username: foobar
74       password: p4ssw0rd
75
76 =head1 DESCRIPTION
77
78 This plugin uses Hyper Estraier
79 (L<http://hyperestraier.sourceforge.net/>) and its P2P Node API to
80 search feed entries aggregated by Plagger.
81
82 =head1 AUTHOR
83
84 Tatsuhiko Miyagawa
85
86 =head1 SEE ALSO
87
88 L<Plagger>, L<http://hyperestraier.sourceforge.net/>, L<Search::Estraier>
89
90 =cut
Note: See TracBrowser for help on using the browser.