[Bio] / FigWebServices / SearchSkeleton.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/SearchSkeleton.cgi

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

revision 1.2, Wed Sep 27 16:57:24 2006 UTC revision 1.3, Fri Sep 29 15:02:43 2006 UTC
# Line 64  Line 64 
64  search, you would specify a class of C<FidSearch>. If this parameter is omitted,  search, you would specify a class of C<FidSearch>. If this parameter is omitted,
65  then all of the advanced search forms will be displayed.  then all of the advanced search forms will be displayed.
66    
67    =item ShowURL
68    
69    If specified, then a URL for repeating the search will be shown as a hyperlink on the
70    results page.
71    
72    =item ShowAliases
73    
74    If specified, then hyperlinked aliases will be shown for each feature.
75    
76  =back  =back
77    
78  =head2 The Cache File  =head2 The Cache File
# Line 74  Line 83 
83  The column contents may contain HTML tags, including hyperlinks and buttons. For best  The column contents may contain HTML tags, including hyperlinks and buttons. For best
84  results, all links should be relative.  results, all links should be relative.
85    
86    Some columns will consist of a doubled percent sign followed by a name, an equal sign,
87    and some text. This tells the display code to call the B<RunTimeColumns> method of
88    the B<SearchHelper> object to compute the column value. This facility is designed for
89    columns that require a lot of time to calculate, so we don't want to calculate them
90    until we absolutely have to display them.
91    
92  It is presumed that the cache file is small, containing no more than a few thousand  It is presumed that the cache file is small, containing no more than a few thousand
93  lines of data. If this is not the case, an entirely different strategy will be  lines of data. If this is not the case, an entirely different strategy will be
94  needed for displaying search results.  needed for displaying search results.
# Line 93  Line 108 
108  use SHSigGenes;  use SHSigGenes;
109  use POSIX qw(ceil);  use POSIX qw(ceil);
110    
 # This next list specifies all of the search classes to be used in the advanced  
 # search form.  
 my @advancedClasses = qw(FidSearch BlastSearch SigGenes);  
111    
112  my ($cgi, $varHash) = ScriptSetup();  my ($cgi, $varHash) = ScriptSetup();
113  eval {  eval {
# Line 115  Line 127 
127          $selfURL .= ($selfURL =~ /\?/ ? '&' : '?');          $selfURL .= ($selfURL =~ /\?/ ? '&' : '?');
128          # Loop through the search classes building a table of contents.          # Loop through the search classes building a table of contents.
129          my @contents = ();          my @contents = ();
130          for my $className (@advancedClasses) {          for my $className (@{$FIG_Config::advanced_classes}) {
131              Trace("Processing $className") if T(3);              Trace("Processing $className") if T(3);
132              my $shelp = GetHelper($cgi, $className);              my $shelp = GetHelper($cgi, $className);
133              push @contents, "<a href=\"${selfURL}Class=$className\">$className</a>: " . $shelp->Description();              push @contents, "<a href=\"${selfURL}Class=$className\">$className</a>: " . $shelp->Description();
# Line 135  Line 147 
147          my $shelp = GetHelper($cgi, $class);          my $shelp = GetHelper($cgi, $class);
148          # Tell the template what the class is.          # Tell the template what the class is.
149          $varHash->{class} = $class;          $varHash->{class} = $class;
150            # Insure we have a page size.
151            if (! $cgi->param("PageSize")) {
152                $cgi->param(-name => 'PageSize', -value => $FIG_Config::results_per_page);
153            }
154          # Display the form, if desired.          # Display the form, if desired.
155          if (! $cgi->param("NoForm")) {          my $formShown = ! $cgi->param("NoForm");
156            if ($formShown) {
157              $varHash->{form} = $shelp->Form();              $varHash->{form} = $shelp->Form();
158          }          }
159            # Declare the result count variable.
160            my $result_count = 0;
161          # Now there are three different directions we can go. If a          # Now there are three different directions we can go. If a
162          # "Search" button has been pressed, then we need to perform a          # "Search" button has been pressed, then we need to perform a
163          # search. If this is a new session and the button has not          # search. If this is a new session and the button has not
# Line 156  Line 175 
175              }              }
176          } else {          } else {
177              # Here we have a button press, so we need to find stuff and              # Here we have a button press, so we need to find stuff and
178              # then display it. First, we set the result count to 0 for              # then display it..
             # future reference.  
179              Trace("Performing the search.") if T(3);              Trace("Performing the search.") if T(3);
180              $cgi->param(-name => "ResultCount", -value => 0);              # Clear the result area.
181              my $result_count = $shelp->Find();              $varHash->{results} = "";
182                # Now we process the showURL thing. If showURL is checked, then
183                # we will display a hyperlink to this search.
184                if ($cgi->param('ShowURL')) {
185                    my $searchURL = $shelp->ComputeSearchURL();
186                    $varHash->{results} .= $cgi->p("<a href=\"$searchURL\">Right-click to save a URL for this search</a>");
187                }
188                $result_count = $shelp->Find();
189              # Check to see what kind of results we got.              # Check to see what kind of results we got.
190              if (! defined($result_count)) {              if (! defined($result_count)) {
191                  # Here an error occurred, so we display the error message.                  # Here an error occurred, so we display the error message.
192                  $varHash->{results} = $cgi->h3("ERROR: " . $shelp->Message());                  $varHash->{results} .= $cgi->h3("ERROR: " . $shelp->Message());
193                    $result_count = 0;
194              } elsif ($result_count == 0) {              } elsif ($result_count == 0) {
195                  # Here nothing matched.                  # Here nothing matched.
196                  $varHash->{results} = $cgi->h3("No match found.");                  $varHash->{results} .= $cgi->h3("No match found.");
197              } else {              } else {
198                  # Here we have results. Save the result count and set up to display                  # Here we have results. Save the result count and set up to display
199                  # the first page of results.                  # the first page of results.
# Line 175  Line 201 
201                  $cgi->param(-name => "Page", -value => 1);                  $cgi->param(-name => "Page", -value => 1);
202                  # Start with a message about how many matches we found.                  # Start with a message about how many matches we found.
203                  my $countText = ($result_count == 1 ? "One match" : "$result_count matches");                  my $countText = ($result_count == 1 ? "One match" : "$result_count matches");
204                  $varHash->{results} = $cgi->h3("$countText found.");                  $varHash->{results} .= $cgi->h3("$countText found.");
205                  # Append the page display.                  # Append the page display.
206                  $varHash->{results} .= DisplayResults($shelp, $cgi);                  $varHash->{results} .= DisplayResults($shelp, $cgi);
207              }              }
# Line 183  Line 209 
209          # Save the result count so that the results helper text appears if it          # Save the result count so that the results helper text appears if it
210          # is needed. This text is in the template, but it's protected by a TMPL_IF          # is needed. This text is in the template, but it's protected by a TMPL_IF
211          # on "result_count".          # on "result_count".
212          $varHash->{result_count} = $cgi->param("ResultCount");          $varHash->{result_count} = $result_count;
213            # If there are no results and the form was shown, add the help text. We are
214            # assuming that if the user got the search to work, he doesn't need help.
215            # In addition, if the form was not shown, a description of how to use it
216            # makes no sense.
217            if (! $result_count && $formShown) {
218                $varHash->{helptext} = $shelp->GetHelpText();
219            }
220      }      }
221  };  };
222  if ($@) {  if ($@) {
# Line 257  Line 290 
290              my @tableRows = ();              my @tableRows = ();
291              my $linesLeft = $pageSize;              my $linesLeft = $pageSize;
292              while ($linesLeft-- > 0 && (my @cols = Tracer::GetLine($sessionH))) {              while ($linesLeft-- > 0 && (my @cols = Tracer::GetLine($sessionH))) {
293                  push @tableRows, \@cols;                  # Check the columns for run-time generation.
294                    my @actual = map { substr($_,0,2) eq "%%" ? $shelp->GetRunTimeValue($_) : $_ } @cols;
295                    # Put the actual data into the table list.
296                    push @tableRows, \@actual;
297              }              }
298              # Now we're ready. We do a page navigator, a spacer, the table, a spacer,              # Now we're ready. We do a page navigator, a spacer, the table, a spacer,
299              # and another page navigator.              # and another page navigator.
# Line 319  Line 355 
355              push @pageThings, PageThing($cgi, $linkPage, $linkPage, $url);              push @pageThings, PageThing($cgi, $linkPage, $linkPage, $url);
356          }          }
357      }      }
358      # Add the forward and back pointers.      # Now add some jump links at the end.
359      my $backPointer = ($startPage <= 1 ? "<<" : PageThing($cgi, "<<", $startPage - 1, $url));      my @forePointers = ();
360      my $forePointer = ($endPage >= $lastPage ? ">>" : PageThing($cgi, ">>", $endPage + 1, $url));      if ($endPage + 1 == $lastPage) {
361            for (my $pg = $endPage + 5; $pg < $lastPage; $pg += 15) {
362                push @forePointers, PageThing($cgi, $pg, $pg, $url);
363            }
364            push @forePointers, PageThing($cgi, ">>", $lastPage, $url);
365        }
366        # Finally, add some jump links at the front.
367        my @backPointers = ();
368        if ($startPage > 1) {
369            for (my $pg = $startPage - 5; $pg > 1; $pg -= 15) {
370                shift @backPointers, PageThing($cgi, $pg, $pg, $url);
371            }
372            shift @backPointers, PageThing($cgi, "<<", 1, $url);
373        }
374      # Put it all together.      # Put it all together.
375      my $retVal = join(" ", $backPointer, @pageThings, $forePointer);      my $retVal = join " ", join(" ... ", @backPointers), @pageThings, join(" ... ", @forePointers);
376      # Return the result.      # Return the result.
377      return $retVal;      return $retVal;
378  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3