1152 |
} |
} |
1153 |
|
|
1154 |
|
|
1155 |
|
=head2 search |
1156 |
|
|
1157 |
|
Search documents which match condition |
1158 |
|
|
1159 |
|
my $nres = $node->search( $cond, $depth ); |
1160 |
|
|
1161 |
|
C<$cond> is C<Search::Estraier::Condition> object, while <$depth> specifies |
1162 |
|
depth for meta search. |
1163 |
|
|
1164 |
|
Function results C<Search::Estraier::NodeResult> object. |
1165 |
|
|
1166 |
|
=cut |
1167 |
|
|
1168 |
|
sub search { |
1169 |
|
my $self = shift; |
1170 |
|
my ($cond, $depth) = @_; |
1171 |
|
return unless ($cond && defined($depth) && $self->{url}); |
1172 |
|
croak "cond mush be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); |
1173 |
|
croak "depth needs number, not '$depth'" unless ($depth =~ m/^\d+$/); |
1174 |
|
|
1175 |
|
|
1176 |
|
} |
1177 |
|
|
1178 |
|
|
1179 |
|
=head2 cond_to_query |
1180 |
|
|
1181 |
|
my $args = $node->cond_to_query( $cond ); |
1182 |
|
|
1183 |
|
=cut |
1184 |
|
|
1185 |
|
sub cond_to_query { |
1186 |
|
my $self = shift; |
1187 |
|
|
1188 |
|
my $cond = shift || return; |
1189 |
|
croak "condition must be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); |
1190 |
|
|
1191 |
|
my @args; |
1192 |
|
|
1193 |
|
if (my $phrase = $cond->phrase) { |
1194 |
|
push @args, 'phrase=' . uri_escape($phrase); |
1195 |
|
} |
1196 |
|
|
1197 |
|
if (my @attrs = $cond->attrs) { |
1198 |
|
for my $i ( 0 .. $#attrs ) { |
1199 |
|
push @args,'attr' . ($i+1) . '=' . uri_escape( $attrs[$i] ); |
1200 |
|
} |
1201 |
|
} |
1202 |
|
|
1203 |
|
if (my $order = $cond->order) { |
1204 |
|
push @args, 'order=' . uri_escape($order); |
1205 |
|
} |
1206 |
|
|
1207 |
|
if (my $max = $cond->max) { |
1208 |
|
push @args, 'max=' . $max; |
1209 |
|
} else { |
1210 |
|
push @args, 'max=' . (1 << 30); |
1211 |
|
} |
1212 |
|
|
1213 |
|
if (my $options = $cond->options) { |
1214 |
|
push @args, 'options=' . $options; |
1215 |
|
} |
1216 |
|
|
1217 |
|
push @args, 'depth=' . $self->{depth} if ($self->{depth}); |
1218 |
|
push @args, 'wwidth=' . $self->{wwidth}; |
1219 |
|
push @args, 'hwidth=' . $self->{hwidth}; |
1220 |
|
push @args, 'awidth=' . $self->{awidth}; |
1221 |
|
|
1222 |
|
return join('&', @args); |
1223 |
|
} |
1224 |
|
|
1225 |
|
|
1226 |
=head2 shuttle_url |
=head2 shuttle_url |
1227 |
|
|