[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.8, Tue Apr 10 06:11:43 2007 UTC revision 1.9, Mon Jul 16 20:04:51 2007 UTC
# Line 4  Line 4 
4    
5      use strict;      use strict;
6      use Tracer;      use Tracer;
     use SearchHelper;  
7      use CGI;      use CGI;
8      use HTML;      use HTML;
9      use Sprout;      use Sprout;
10      use FeatureData;      use RHFeatures;
11      use FeatureQuery;      use base 'SearchHelper';
   
     our @ISA = qw(SearchHelper);  
12    
13  =head1 Simple Keyword Search Feature Search Helper  =head1 Simple Keyword Search Feature Search Helper
14    
# Line 86  Line 83 
83      # Declare a variable to hold the table rows.      # Declare a variable to hold the table rows.
84      my @rows = ();      my @rows = ();
85      # The first row is for the keyword search expression.      # The first row is for the keyword search expression.
86      my $expressionString = $cgi->param('keywords') || "";      push @rows, RHFeatures::WordSearchRow($self);
     push @rows, $cgi->Tr($cgi->td("Search Words"),  
                          $cgi->td($cgi->textfield(-name => 'keywords',  
                                                   -value => $expressionString,  
                                                   -size => 40)),  
                          $cgi->td($cgi->submit(-name => 'Alternate',  
                                                -value => 'Advanced',  
                                                -class => 'button')),  
                         );  
87      # The second row is for special options.      # The second row is for special options.
88      push @rows, FeatureQuery::SpecialOptions($self);      push @rows, RHFeatures::FeatureFilterFormRows($self, 'options');
89      # The last row is for the submit button.      # The last row is for the submit button.
90      push @rows, $self->SubmitRow();      push @rows, $self->SubmitRow();
91      # 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
# Line 144  Line 133 
133      # Declare the return variable. If it remains undefined, the caller will      # Declare the return variable. If it remains undefined, the caller will
134      # know that an error occurred.      # know that an error occurred.
135      my $retVal;      my $retVal;
136      # Get the keyword list and validate it.      # Get the result helper.
137      my $keywords = $cgi->param('keywords') || "";      my $rhelp = RHFeatures->new($self);
138      if ($self->ValidateKeywords($keywords, 1)) {      # Validate the filtering parameters.
139          # We have good keywords. Initialize the session file.      $rhelp->KeywordsRequired();
140          $self->OpenSession();      if ($rhelp->Valid()) {
141          # Initialize the result counter.          # Initialize the result counter.
142          $retVal = 0;          $retVal = 0;
143            # Get the default columns.
144            $self->DefaultColumns($rhelp);
145            Trace("Column list is " . join(", ", @{$rhelp->GetColumnHeaders()})) if T(3);
146            # Start the output session.
147            $self->OpenSession($rhelp);
148            # Get the keywords.
149            my $keywords = $cgi->param('keywords') || '';
150          # Check for groups.          # Check for groups.
151          my @groups = $cgi->param('group');          my @groups = $cgi->param('group');
152          if (@groups) {          if (@groups) {
# Line 161  Line 157 
157                  my $query = $sprout->Search($keywords, 0, ['Feature', 'HasFeature', 'Genome'],                  my $query = $sprout->Search($keywords, 0, ['Feature', 'HasFeature', 'Genome'],
158                                              "Genome(primary-group) = ?", [$group]);                                              "Genome(primary-group) = ?", [$group]);
159                  Trace("Processing results.") if T(3);                  Trace("Processing results.") if T(3);
160                  $retVal += $self->ProcessQuery($query);                  $retVal += $self->ProcessQuery($rhelp, $query);
161                  Trace("Results processed.") if T(3);                  Trace("Results processed.") if T(3);
162              }              }
163          } else {          } else {
# Line 170  Line 166 
166              $self->PrintLine("Submitting search query for all genomes.<br />");              $self->PrintLine("Submitting search query for all genomes.<br />");
167              my $query = $sprout->Search($keywords, 0, ['Feature']);              my $query = $sprout->Search($keywords, 0, ['Feature']);
168              Trace("Processing results.") if T(3);              Trace("Processing results.") if T(3);
169              $retVal += $self->ProcessQuery($query);              $retVal += $self->ProcessQuery($rhelp, $query);
170              Trace("Results processed.") if T(3);              Trace("Results processed.") if T(3);
171          }          }
172          # Close the session file.          # Close the session file.
# Line 181  Line 177 
177      return $retVal;      return $retVal;
178  }  }
179    
180    =head3 SearchTitle
181    
182    C<< my $titleHtml = $shelp->SearchTitle(); >>
183    
184    Return the display title for this search. The display title appears above the search results.
185    If no result is returned, no title will be displayed. The result should be an html string
186    that can be legally put inside a block tag such as C<h3> or C<p>.
187    
188    =cut
189    
190    sub SearchTitle {
191        # Get the parameters.
192        my ($self) = @_;
193        # Compute the title.
194        my $cgi = $self->Q();
195        my $words = $cgi->param('keywords');
196        my $retVal = "Keyword Search for $words.";
197        # Return it.
198        return $retVal;
199    }
200    
201  =head3 Description  =head3 Description
202    
203  C<< my $htmlText = $shelp->Description(); >>  C<< my $htmlText = $shelp->Description(); >>
# Line 200  Line 217 
217    
218  =head3 ProcessQuery  =head3 ProcessQuery
219    
220  C<< my $count = $shelp->ProcessQuery($query); >>  C<< my $count = $shelp->ProcessQuery($rhelp, $query); >>
221    
222  Run through the results of a query, sending all the features retrieved to the output  Run through the results of a query, sending all the features retrieved to the output
223  cache. The number of features found will be returned to the caller.  cache. The number of features found will be returned to the caller.
224    
225  =over 4  =over 4
226    
227    =item rhelp
228    
229    Current result helper object, which should be B<RHFeatures>.
230    
231  =item query  =item query
232    
233  A B<DBQuery> object that returns features.  A B<DBQuery> object that returns features.
# Line 221  Line 242 
242    
243  sub ProcessQuery {  sub ProcessQuery {
244      # Get the parameters.      # Get the parameters.
245      my ($self, $query) = @_;      my ($self, $rhelp, $query) = @_;
246      my $cgi = $self->Q();      my $cgi = $self->Q();
247      # Clear the result counter.      # Clear the result counter.
248      my $retVal = 0;      my $retVal = 0;
249      $self->PrintLine("Processing query results.<br />");      $self->PrintLine("Processing query results.<br />");
     # Create a feature data object for storing each result.  
     my $fd = FeatureData->new($self);  
250      Trace("Starting feature loop.") if T(3);      Trace("Starting feature loop.") if T(3);
251      # Loop through all the records returned by the query.      # Loop through all the records returned by the query.
252      while (my $record = $query->Fetch()) {      while (my $record = $query->Fetch()) {
253            # Compute the sort key.
254            my $sort = $rhelp->SortKey($record);
255          # Store this feature.          # Store this feature.
256          $fd->Store($record);          $rhelp->PutData($sort, $record->PrimaryValue('Feature(id)'), $record);
         # Send it to the output.  
         $self->PutFeature($fd);  
257          # Increment the result counter.          # Increment the result counter.
258          $retVal++;          $retVal++;
259          if ($retVal % 100 == 0) {          if ($retVal % 100 == 0) {

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3