[Bio] / Sprout / SHWordSearch.pm Repository:
ViewVC logotype

Diff of /Sprout/SHWordSearch.pm

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

revision 1.1, Mon Oct 16 07:46:24 2006 UTC revision 1.8, Tue Apr 10 06:11:43 2007 UTC
# Line 69  Line 69 
69    
70  =head3 Form  =head3 Form
71    
72  C<< my $html = $shelp->Include(); >>  C<< my $html = $shelp->Form(); >>
73    
74  Generate the HTML for a form to request a new search.  Generate the HTML for a form to request a new search.
75    
# Line 88  Line 88 
88      # The first row is for the keyword search expression.      # The first row is for the keyword search expression.
89      my $expressionString = $cgi->param('keywords') || "";      my $expressionString = $cgi->param('keywords') || "";
90      push @rows, $cgi->Tr($cgi->td("Search Words"),      push @rows, $cgi->Tr($cgi->td("Search Words"),
91                           $cgi->td({colspan => 2}, $cgi->textfield(-name => 'keywords',                           $cgi->td($cgi->textfield(-name => 'keywords',
92                                                                    -value => $expressionString,                                                                    -value => $expressionString,
93                                                                    -size => 40)));                                                    -size => 40)),
94      # The other row is for the submit button.                           $cgi->td($cgi->submit(-name => 'Alternate',
95                                                   -value => 'Advanced',
96                                                   -class => 'button')),
97                            );
98        # The second row is for special options.
99        push @rows, FeatureQuery::SpecialOptions($self);
100        # The last row is for the submit button.
101      push @rows, $self->SubmitRow();      push @rows, $self->SubmitRow();
102      # Finally, if groups are specified, we include them as hidden fields and display      # Finally, if groups are specified, we include them as hidden fields and display
103      # an explanation.      # an explanation.
# Line 138  Line 144 
144      # Declare the return variable. If it remains undefined, the caller will      # Declare the return variable. If it remains undefined, the caller will
145      # know that an error occurred.      # know that an error occurred.
146      my $retVal;      my $retVal;
147      # Get the keyword list. We need to prove that there is at least one keyword      # Get the keyword list and validate it.
     # that does not begin with a "-".  
148      my $keywords = $cgi->param('keywords') || "";      my $keywords = $cgi->param('keywords') || "";
149      my @wordList = split /\s+/, $keywords;      if ($self->ValidateKeywords($keywords, 1)) {
     my @plusWords = grep { $_ =~ /^[^\-]/ } @wordList;  
     if (! @wordList) {  
         $self->SetMessage("No search words specified.");  
     } elsif (! @plusWords) {  
         $self->SetMessage("At least one keyword must be positive. All the keywords entered are preceded by minus signs.");  
     } else {  
150          # We have good keywords. Initialize the session file.          # We have good keywords. Initialize the session file.
151          $self->OpenSession();          $self->OpenSession();
152          # Initialize the result counter.          # Initialize the result counter.
# Line 157  Line 156 
156          if (@groups) {          if (@groups) {
157              # Here we do the search a group at a time.              # Here we do the search a group at a time.
158              for my $group (@groups) {              for my $group (@groups) {
159                    Trace("Starting the search.") if T(3);
160                    $self->PrintLine("Submitting search query for $group.<br />");
161                  my $query = $sprout->Search($keywords, 0, ['Feature', 'HasFeature', 'Genome'],                  my $query = $sprout->Search($keywords, 0, ['Feature', 'HasFeature', 'Genome'],
162                                              "Genome(primary-group) = ?", [$group]);                                              "Genome(primary-group) = ?", [$group]);
163                    Trace("Processing results.") if T(3);
164                  $retVal += $self->ProcessQuery($query);                  $retVal += $self->ProcessQuery($query);
165                    Trace("Results processed.") if T(3);
166              }              }
167          } else {          } else {
168              # Here we do one search just for features.              # Here we do one search just for features.
169                Trace("Starting the search.") if T(3);
170                $self->PrintLine("Submitting search query for all genomes.<br />");
171              my $query = $sprout->Search($keywords, 0, ['Feature']);              my $query = $sprout->Search($keywords, 0, ['Feature']);
172                Trace("Processing results.") if T(3);
173              $retVal += $self->ProcessQuery($query);              $retVal += $self->ProcessQuery($query);
174                Trace("Results processed.") if T(3);
175          }          }
176          # Close the session file.          # Close the session file.
177          $self->CloseSession();          $self->CloseSession();
178            Trace("Session closed.") if T(3);
179      }      }
180      # Return the result count.      # Return the result count.
181      return $retVal;      return $retVal;
# Line 187  Line 195 
195      # Get the parameters.      # Get the parameters.
196      my ($self) = @_;      my ($self) = @_;
197      # Return the result.      # Return the result.
198      return "Search for features based on keywords.";      return "Search for genes based on keywords.";
199  }  }
200    
201  =head3 ProcessQuery  =head3 ProcessQuery
# Line 214  Line 222 
222  sub ProcessQuery {  sub ProcessQuery {
223      # Get the parameters.      # Get the parameters.
224      my ($self, $query) = @_;      my ($self, $query) = @_;
225        my $cgi = $self->Q();
226      # Clear the result counter.      # Clear the result counter.
227      my $retVal = 0;      my $retVal = 0;
228        $self->PrintLine("Processing query results.<br />");
229      # Create a feature data object for storing each result.      # Create a feature data object for storing each result.
230      my $fd = FeatureData->new($self);      my $fd = FeatureData->new($self);
231        Trace("Starting feature loop.") if T(3);
232      # Loop through all the records returned by the query.      # Loop through all the records returned by the query.
233      while (my $record = $query->Fetch()) {      while (my $record = $query->Fetch()) {
234          # Store this feature.          # Store this feature.
# Line 226  Line 237 
237          $self->PutFeature($fd);          $self->PutFeature($fd);
238          # Increment the result counter.          # Increment the result counter.
239          $retVal++;          $retVal++;
240            if ($retVal % 100 == 0) {
241                $self->PrintLine("$retVal results processed.<br />");
242            }
243      }      }
244        $self->PrintLine("Results found: $retVal.<br />");
245      # Return the counter.      # Return the counter.
246      return $retVal;      return $retVal;
247  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3