/[webpac2]/trunk/vhost/webpac2.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/vhost/webpac2.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1226 by dpavlin, Thu Jun 11 17:21:10 2009 UTC revision 1227 by dpavlin, Thu Jun 11 18:55:53 2009 UTC
# Line 156  sub search_form { Line 156  sub search_form {
156  #                       -linebreak => 0,  #                       -linebreak => 0,
157                  ),                  ),
158                  textfield( -name => 'search' ),                  textfield( -name => 'search' ),
159                  popup_menu( -name => 'attr_operator', %$attr_operators ),                  $attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '',
160                  submit,                  submit,
161                  hidden( -name => 'entries_per_page', -default => $entries_per_page ),                  hidden( -name => 'entries_per_page', -default => $entries_per_page ),
162                  # we need current_page fixed at 1 so that every submit through form will reset it                  # we need current_page fixed at 1 so that every submit through form will reset it
# Line 195  if ( my $search = param('search') ) { Line 195  if ( my $search = param('search') ) {
195          $swish->abort_last_error if $swish->Error;          $swish->abort_last_error if $swish->Error;
196    
197          my @search = ();          my @search = ();
198            my @attrs = param('attr');
199            my $op = param('attr_operator');
200    
201          if ( $search =~ m{(=|"|AND|OR)} ) {          if ( $search =~ m{(=|"|AND|OR)} ) {
202                  push @search, $search;                  push @search, $search;
203          } elsif ( my $op = param('attr_operator') ) {          } elsif ( @attrs ) {
204                  my $attr = param('attr') || 'all';  
205                  my $v = $search;                  $op ||= 'Q*';
206                  $v =~ s/^\s+//;                  my @or;
207                  warn "-- v: $v\n";                  foreach my $attr ( @attrs ) {
208                  sub rewrite {                          my $v = $search;
209                          my ( $whitespace, $v ) = @_;                          $v =~ s/^\s+//;
210                          warn "## filter $op $whitespace $v\n";                          warn "-- v: $v\n";
211                          my $template = $op;                          sub rewrite {
212                             $template =~ s{Q}{$v};                                  my ( $attr, $whitespace, $v ) = @_;
213                          $whitespace = " AND " if $whitespace;                                  warn "## filter $op $whitespace $v\n";
214                                    my $template = $op;
215                          return                                     $template =~ s{Q}{$v};
216                                  $whitespace .                                  $whitespace = " AND " if $whitespace;
217                                  $attr . '="' . $template . '"';  
218                                  ;                                  return
219                  };                                          $whitespace .
220                  if ( $op =~ m{\s} ) {                                          $attr . '="' . $template . '"';
221                          my $template = $op;                                          ;
222                             $template =~ s{Q}{$v};                          };
223                          $v = $attr . '="' . $template . '"';                          if ( $op =~ m{\s} ) {
224                  } else {                                  my $template = $op;
225                          $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge;                                     $template =~ s{Q}{$v};
226                                    $v = $attr . '="' . $template . '"';
227                            } else {
228                                    $v =~ s{(\s*)(\S+)}{rewrite($attr,$1,$2)}ge;
229                            }
230    
231                            push @or, $v;
232                    
233                  }                  }
234                    push @search, '(' . join(') OR (', @or) . ')';
235    
                 push @search, $v;  
           
                 my @only_input = param('only_input');  
                 push @search, '((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input;  
236          } else {          } else {
237                  push @search, "all=\"$search\"";                  push @search, "all=\"$search\"";
238          }          }
239    
240          my $q = '(' . join(') AND (', @search) . ')';          my $q = '(' . join(') AND (', @search) . ')';
241          $q =~ s{\(\((.+)\)\)}{($1)};  
242            my @only_input = param('only_input');
243            $q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input;
244    
245          warn "# query: $q\n";          warn "# query: $q\n";
246          my $swish_results = $swish->query( $q );          my $swish_results = $swish->query( $q );
247    

Legend:
Removed from v.1226  
changed lines
  Added in v.1227

  ViewVC Help
Powered by ViewVC 1.1.26