--- trunk/Estraier.pm 2006/01/06 12:48:14 50 +++ trunk/Estraier.pm 2006/01/06 13:19:50 51 @@ -1152,6 +1152,76 @@ } +=head2 search + +Search documents which match condition + + my $nres = $node->search( $cond, $depth ); + +C<$cond> is C object, while <$depth> specifies +depth for meta search. + +Function results C object. + +=cut + +sub search { + my $self = shift; + my ($cond, $depth) = @_; + return unless ($cond && defined($depth) && $self->{url}); + croak "cond mush be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); + croak "depth needs number, not '$depth'" unless ($depth =~ m/^\d+$/); + + +} + + +=head2 cond_to_query + + my $args = $node->cond_to_query( $cond ); + +=cut + +sub cond_to_query { + my $self = shift; + + my $cond = shift || return; + croak "condition must be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); + + my @args; + + if (my $phrase = $cond->phrase) { + push @args, 'phrase=' . uri_escape($phrase); + } + + if (my @attrs = $cond->attrs) { + for my $i ( 0 .. $#attrs ) { + push @args,'attr' . ($i+1) . '=' . uri_escape( $attrs[$i] ); + } + } + + if (my $order = $cond->order) { + push @args, 'order=' . uri_escape($order); + } + + if (my $max = $cond->max) { + push @args, 'max=' . $max; + } else { + push @args, 'max=' . (1 << 30); + } + + if (my $options = $cond->options) { + push @args, 'options=' . $options; + } + + push @args, 'depth=' . $self->{depth} if ($self->{depth}); + push @args, 'wwidth=' . $self->{wwidth}; + push @args, 'hwidth=' . $self->{hwidth}; + push @args, 'awidth=' . $self->{awidth}; + + return join('&', @args); +} + =head2 shuttle_url