Show
Ignore:
Timestamp:
11/30/07 17:00:59 (1 year ago)
Author:
joshr
Message:

tabs replaced with spaces. We use ts=4 sw=4 in vi.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Swishetest/trunk/DoSearch.pm

    r1959 r1965  
    55use warnings; 
    66 
    7 my %swishes = ();      # map of filename -> SWISH::API 
     7my %swishes = ();   # map of filename -> SWISH::API 
    88 
    99# given an index filename and a query, opens the index if needed,  
     
    1212 
    1313sub open_index {  
    14        my $index = shift; 
    15        if (!exists($swishes{$index})) { 
    16                my $swish = $swishes{$index} = SWISH::API->new( $index ); 
    17                die "$0: index $index could not be opened.\n" unless $swish; 
    18                print STDERR "Index $index opened\n" if $ENV{TEST_VERBOSE}; 
    19        
    20        return 1; 
     14    my $index = shift; 
     15    if (!exists($swishes{$index})) { 
     16        my $swish = $swishes{$index} = SWISH::API->new( $index ); 
     17        die "$0: index $index could not be opened.\n" unless $swish; 
     18        print STDERR "Index $index opened\n" if $ENV{TEST_VERBOSE}; 
     19   
     20    return 1; 
    2121} 
    2222 
    2323sub close_index { 
    24        my $index = shift; 
    25        if (exists($swishes{$index})) { 
    26                delete $swishes{$index};        # remove from the hash, should close it 
    27        } else {  
    28                die "$0: index $index was not open.\n"; 
    29        
     24    my $index = shift; 
     25    if (exists($swishes{$index})) { 
     26        delete $swishes{$index};    # remove from the hash, should close it 
     27    } else {  
     28        die "$0: index $index was not open.\n"; 
     29   
    3030} 
    3131sub do_search { 
    32         my ($index, $query) = @_;        
    33        my @r = (); 
    34        #return @r unless $query; 
    35        my $swish; 
    36        eval { 
    37                if (exists($swishes{$index})) { 
    38                        $swish = $swishes{$index}; 
    39                } else {  
    40                        #$swish = $swishes{$index} = SWISH::API->new( $index ); 
    41                        die "$0: index $index was not opened.\n"; 
    42                
    43                #print STDERR "Searching for $query\n" if $ENV{TEST_VERBOSE}; 
    44                my $results = $swish->Query( $query ); 
    45                my @props = map { $_->Name } ($swish->PropertyList( $index ) ); 
    46                if ($swish->Error()) { 
    47                        #print STDERR "$0: Error searching for $query: " . $swish->ErrorString(); 
    48                        return @r; 
    49                
     32    my ($index, $query) = @_;    
     33    my @r = (); 
     34    #return @r unless $query; 
     35    my $swish; 
     36    eval { 
     37        if (exists($swishes{$index})) { 
     38            $swish = $swishes{$index}; 
     39        } else {  
     40            #$swish = $swishes{$index} = SWISH::API->new( $index ); 
     41            die "$0: index $index was not opened.\n"; 
     42       
     43        #print STDERR "Searching for $query\n" if $ENV{TEST_VERBOSE}; 
     44        my $results = $swish->Query( $query ); 
     45        my @props = map { $_->Name } ($swish->PropertyList( $index ) ); 
     46        if ($swish->Error()) { 
     47            #print STDERR "$0: Error searching for $query: " . $swish->ErrorString(); 
     48            return @r; 
     49       
    5050 
    51                while ( my $result = $results->NextResult() ) { 
    52                        my %h; 
    53                        for my $p (@props) { $h{$p} = $result->Property($p); } 
    54                        push(@r, \%h); 
    55                
    56        };      # end eval{} 
    57        if ($@) { 
    58                my $str = "$0: test failed: $@"; 
    59                if ($swish && $swish->Error()) { 
    60                        $str .= " (" . $swish->ErrorString() . ")"; 
    61                
    62        
    63        return @r; 
     51        while ( my $result = $results->NextResult() ) { 
     52            my %h; 
     53            for my $p (@props) { $h{$p} = $result->Property($p); } 
     54            push(@r, \%h); 
     55       
     56    };  # end eval{} 
     57    if ($@) { 
     58        my $str = "$0: test failed: $@"; 
     59        if ($swish && $swish->Error()) { 
     60            $str .= " (" . $swish->ErrorString() . ")"; 
     61       
     62   
     63    return @r; 
    6464} 
    6565