11 |
|
|
12 |
my ( $analyzer, $store, $writer ); |
my ( $analyzer, $store, $writer ); |
13 |
|
|
14 |
my $debug = 0; |
my $debug = 1; |
15 |
|
|
16 |
sub create { |
sub create { |
17 |
|
|
68 |
my $v = $i->$c; |
my $v = $i->$c; |
69 |
|
|
70 |
if ( ref($v) ne '' ) { |
if ( ref($v) ne '' ) { |
71 |
if ($i->$c->can('id')) { |
|
72 |
$v = $i->$c->id; |
foreach my $f_c ( qw/id name title/ ) { |
73 |
warn " # $c = $v [id]\n" if ($debug); |
if ( $i->$c->can( $f_c ) ) { |
74 |
$doc->add(Lucene::Document::Field->Keyword( $c, $v )); |
my $f_v = $i->$c->$f_c || $i->$c->{values}->{ $f_c }; |
75 |
} elsif ($v->isa('Jifty::DateTime')) { |
my $col = $c . '_' . $f_c; |
76 |
|
if ( $f_v ) { |
77 |
|
warn " # $col = $f_v\n" if ($debug); |
78 |
|
$doc->add(Lucene::Document::Field->Text( $col, $f_v )); |
79 |
|
} else { |
80 |
|
warn " . $col is NULL\n" if ($debug); |
81 |
|
} |
82 |
|
} |
83 |
|
} |
84 |
|
|
85 |
|
if ($v->isa('Jifty::DateTime')) { |
86 |
warn " d $c = $v\n" if ($debug); |
warn " d $c = $v\n" if ($debug); |
87 |
$doc->add(Lucene::Document::Field->Keyword( $c, "$v" )); |
$doc->add(Lucene::Document::Field->Keyword( $c, "$v" )); |
88 |
} else { |
} else { |
100 |
warn " * $c = $v\n" if ($debug); |
warn " * $c = $v\n" if ($debug); |
101 |
} else { |
} else { |
102 |
$doc->add(Lucene::Document::Field->Text( $c, $v )); |
$doc->add(Lucene::Document::Field->Text( $c, $v )); |
103 |
warn " + $c = $v\n" if ($debug); |
warn " + $c = ", $self->snippet( 50, $v ), "\n" if ($debug); |
104 |
} |
} |
105 |
} |
} |
106 |
|
|
190 |
$SIG{'INT'} = \&_signal; |
$SIG{'INT'} = \&_signal; |
191 |
$SIG{'QUIT'} = \&_signal; |
$SIG{'QUIT'} = \&_signal; |
192 |
|
|
193 |
|
|
194 |
|
=head2 snippet |
195 |
|
|
196 |
|
my $short = $self->snippet( 50, $text ); |
197 |
|
|
198 |
|
|
199 |
|
=cut |
200 |
|
|
201 |
|
sub snippet { |
202 |
|
my $self = shift; |
203 |
|
|
204 |
|
my $len = shift or die "no len?"; |
205 |
|
my $m = join(" ", @_); |
206 |
|
|
207 |
|
$m =~ s/\s+/ /gs; |
208 |
|
|
209 |
|
if (length($m) > $len) { |
210 |
|
return substr($m,0,$len) . '...'; |
211 |
|
} else { |
212 |
|
return $m; |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
1; |
1; |