Skip to main content.
home | support | download

Back to List Archive

(patch) metaname searchboxes

From: Dan Debertin <debertin(at)not-real.umn.edu>
Date: Wed Jul 30 2003 - 16:10:07 GMT
It looks like some sites that are using swish-e are doing this, but
the feature doesn't appear to have made it back into swish.cgi.

This patch adds the capability for additional search boxes to allow
matching based on multiple metanames, which can be optionally joined
by either AND or OR logic. This is nice for queries like "pages that
contain the word `liver', by (DC.Creator) `Bob Cook', published on
(DC.Date) 2000-01-01". You can already do this with select_by_meta,
but that doesn't let the user determine their own criteria.

Unfortunately, I haven't yet had time to add it to any of the template
modules but TemplateDefault.pm.

Dan
-- 
Dan Debertin                             Unix Systems Admin
Diehl Hall #203B			 University of Minnesota
(612)626-6468				 Bio-Medical Library
debertin@umn.edu


--- swish.cgi    2003-07-28 11:54:00.610019000 -0500
+++ swish.cgi.new   2003-07-30 10:57:31.930016000 -0500
@@ -426,6 +427,19 @@
             },
             description => 'Limit search to these areas: ',
         },
+               # Alternatively, the same purpose can be fulfilled using 
+               # fill-in boxes. 
+               Xselect_by_meta_forms => {
+                       num_forms => 3,   # How many entry boxes
+                       and_or_menus  => 1,  # Side boxes to select 'AND' or 'OR' logic
+                       default_and   => 1,  # Sets the default for the and/or boxes. If you're not
+                                                                # using and_or_menus, be sure to se
t this so the correct
+                                                                # logic gets used.
+                       metanames     => [qw/DC.creator DC.description/],  # metanames to use
+                       # Labels must line up one-for-one with metanames.
+                       labels        => [qw/Creator Description/],
+                       description   => 'Limit by element: '
+               },
 
 
 
@@ -1340,11 +1354,33 @@
     # Should look into doing:
     # $query = "( $query ) AND " . $limits->{metaname} . '=(' . join( ' OR ', @limits ) . ')';
 
    if ( @limits && ref $limits eq 'HASH' && $limits->{metaname} ) {
        $query .= ' and ' . $limits->{metaname} . '=(' . join( ' or ', @limits ) . ')';
    }

+    my $sbmf_limits = $self->config('select_by_meta_forms');
+    if (ref $sbmf_limits eq 'HASH' && $sbmf_limits->{'metanames'} && $q->param('metaselect_val_1'))
 {
+               $query .= ' and (';
+           for(my $c = 1; $c <= $sbmf_limits->{'num_forms'}; $c++) {
+                       if($q->param('metaselect_val_' . $c)) {
+                               $query .= $q->param('metaselect_attr_' . $c) . '=' .
+                                     $q->param('metaselect_val_' . $c) . " ";
+                           if($q->param('metaselect_val_' . ($c + 1))) {
+                               if($sbmf_limits->{'and_or_menus'}) {
+                                       $query .= ($q->param('metaselect_andor_' . $c) eq '1' ?
+                                                                  'AND ' :
+                                                                  'OR ')
+                               }
+                               else {
+                                       $query .= ($sbmf_limits->{'default_and'} ? 'AND ' : 'OR ')
+                                        }
+                               }
+                       }
+               }
+               $query .= ")";
+       }
     $self->swish_command('-w', $query );
 
     return 1;
 



--- TemplateDefault.pm   2003-05-13 01:11:33.000000000 -0500
+++ TemplateDefault.pm.new        2003-07-30 10:39:18.620024000 -0500
@@ -100,6 +100,8 @@
     my $sorts               = get_sort_select_list( $results );
     my $select_index        = get_index_select_list( $results );
     my $limit_select        = get_limit_select( $results );
+    my $meta_select_forms   = get_meta_select_forms( $results );
     
     my $date_ranges_select  = $results->get_date_ranges;
 
@@ -115,6 +117,7 @@
         $select_index
         $limit_select
         $date_ranges_select
+        $meta_select_forms
 EOF
 
     my $extra = $results->config('extra_fields');
@@ -377,6 +380,40 @@
         '<br>';
 }
 
+sub get_meta_select_forms {
+  my ( $results ) = @_;
+
+  my $metaselects = $results->config('select_by_meta_forms');
+  return '' unless $metaselects;
+
+  my $q = $results->CGI;
+  my %labels = ();
+  @labels{@{$metaselects->{'metanames'}}} = @{$metaselects->{'labels'}};
+
+  return join "<br/>",
+    "<br/>" . $metaselects->{'description'},
+      (map { 
+       $q->popup_menu(
+                      -name    => 'metaselect_attr_' . $_,
+                      -values  => $metaselects->{'metanames'},
+                      -default => $metaselects->{'metanames'}->[0],
+                          -labels  => \%labels
+                     ) .
+                       "<input maxlength=\"200\" name=\"metaselect_val_" . $_ . "\" size=\"16\" typ
e=\"text\"/>" .
+                         ($metaselects->{'and_or_menus'} ? 
+                          $q->popup_menu(
+                                         -name    => 'metaselect_andor_' . $_,
+                                         -values  => ['1', '0'],
+                                         -default => ($metaselects->{'default_and'} ?
+                                                      '1' :
+                                                      '0'),
+                                         -labels  => { '1' => 'AND', '0' => 'OR' }) :
+                          "")
+                       } 1..$metaselects->{'num_forms'});
+}
+
+
+
 sub get_sort_select_list {
     my ( $results ) = @_;
 
Received on Wed Jul 30 16:11:43 2003