Changeset 2876


Ignore:
Timestamp:
07/08/10 22:45:27 (19 months ago)
Author:
karpet
Message:

fixes for term_expander

Location:
Search-Query/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Search-Query/trunk/lib/Search/Query/Parser.pm

    r2845 r2876  
    577577    } 
    578578 
     579    my $query_class = $self->{query_class}; 
     580 
    579581    $query->walk( 
    580582        sub { 
     
    589591                $clause->value( $newterms[0] ); 
    590592            } 
     593            elsif ( @newterms > 1 ) { 
     594 
     595                # turn $clause into a tree 
     596                my $class     = blessed($clause); 
     597                my $op        = $clause->op; 
     598                my $field     = $clause->field; 
     599                my $proximity = $clause->proximity; 
     600                my $quote     = $clause->quote; 
     601 
     602                #warn "before tree: " . dump $tree; 
     603 
     604                #warn "code clause: " . dump $clause; 
     605                my @subclauses; 
     606                for my $term (@newterms) { 
     607                    push( 
     608                        @subclauses, 
     609                        $class->new( 
     610                            field     => $field, 
     611                            op        => $op, 
     612                            value     => $term, 
     613                            quote     => $quote, 
     614                            proximity => $proximity, 
     615                        ) 
     616                    ); 
     617                } 
     618 
     619                # OR the fields together. TODO optional? 
     620 
     621                # we must bless here because 
     622                # our bool op keys are not methods. 
     623                my $subclause = bless( { "" => \@subclauses }, $query_class ); 
     624                $subclause->init( %{ $self->query_class_opts }, 
     625                    parser => $self ); 
     626 
     627                $clause->op('()'); 
     628                $clause->value($subclause); 
     629            } 
    591630            else { 
    592                 $clause->value( '(' . join( ' OR ', @newterms ) . ')' ); 
     631                $clause->value( $newterms[0] ); 
    593632            } 
    594633 
  • Search-Query/trunk/t/07-term-expander.t

    r2845 r2876  
    1515 
    1616ok( my $query = $parser->parse("foo=bar"), "parse foo=bar" ); 
    17 is( "$query", qq/+foo=(one OR two OR three OR bar)/, "query expanded" ); 
     17my $expect = qq/+(foo=one foo=two foo=three foo=bar)/; 
     18is( "$query", $expect, "query expanded" ); 
    1819 
Note: See TracChangeset for help on using the changeset viewer.