clean
[sgn.git] / lib / SGN / Controller / Search.pm
blob0ef03314adebf851a9ec768163583c4ce6f16a1d
1 package SGN::Controller::Search;
2 use Moose;
3 use namespace::autoclean;
5 use CXGN::Search::CannedForms;
6 use CXGN::Page::Toolbar::SGN;
7 use CXGN::Glossary qw(get_definitions create_tooltips_from_text);
9 # this is suboptimal
10 use CatalystX::GlobalContext qw( $c );
12 BEGIN {extends 'Catalyst::Controller'; }
14 =head1 NAME
16 SGN::Controller::Search - SGN Search Controller
18 =head1 DESCRIPTION
20 SGN Search Controller. Most, but not all, search code interacts with this
21 controller. This controller defines the general search interface that used to
22 live at direct_search.pl, and links to all other kinds of search.
24 =cut
26 sub auto : Private {
27 $_[1]->stash->{template} = '/search/stub.mas';
30 =head1 PUBLIC ACTIONS
32 =cut
34 =head2 glossary
36 Public path: /search/glossary
38 Runs the glossary search.
40 =cut
42 sub glossary : Path('/search/glossary') :Args() {
43 my ( $self, $c, $term ) = @_;
44 my $response;
45 if($term){
46 my @defs = get_definitions($term);
47 unless (@defs){
48 $response = "<p>Your term was not found. <br> The term you searched for was $term.</p>";
49 } else {
50 $response = "<hr /><dl><dt>$term</dt>";
51 for my $d (@defs){
52 $response .= "<dd>$d</dd><br />";
54 $response .= "</dl>";
56 } else {
57 $response =<<DEFAULT;
58 <hr />
59 <h2>Glossary search</h2>
60 <form action="#" method='get' name='glossary'>
61 <b>Search the glossary by term:</b>
62 <input type = 'text' name = 'getTerm' size = '50' tabindex='0' />
63 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
64 <input type = 'submit' value = 'Lookup' /></form>
65 <script type="text/javascript" language="javascript">
66 document.glossary.getTerm.focus();
67 </script>
69 DEFAULT
72 $c->stash(
73 content => $response,
78 =head2 old_direct_search
80 Public path: /search/direct_search.pl
82 Redirects to the new search functionality.
84 =cut
86 sub old_direct_search : Path('/search/direct_search.pl') {
87 my ( $self, $c ) = @_;
89 my $term = $c->req->param('search');
90 # map the old direct_search param to the new scheme
91 $term = {
92 cvterm_name => 'qtl',
94 qtl => 'phenotypes/qtl',
95 marker => 'markers',
97 # expression
98 platform => 'expression/platform',
99 template => 'expression/template',
100 experiment => 'expression/experiment',
102 # transcripts
103 est_library => 'transcripts/est_library',
104 est => 'transcripts/est',
105 unigene => 'transcripts/unigene',
106 library => 'transcripts/est_library',
108 template_experiment_platform => 'expression',
110 bacs => 'genomic/clones',
112 phenotype_qtl_trait => 'phenotypes',
115 }->{$term} || $term;
116 $c->res->redirect('/search/'.$term, 301 );
119 =head2 search_index
121 Public path: /search/index.pl, /search/
123 Display a search index page.
125 =cut
127 sub search_index : Path('/search/index.pl') Path('/search') Args(0) {
128 my ( $self, $c ) = @_;
130 $c->stash(
131 content => $c->view('Toolbar')->index_page('search'),
133 $c->forward('View::Mason');
136 sub family_search : Path('/search/family') Args(0) {
137 $_[1]->stash->{content} = CXGN::Search::CannedForms->family_search_form();
140 sub marker_search : Path('/search/markers') Args(0) {
141 my ( $self, $c ) = @_;
142 my $dbh = $c->dbc->dbh;
143 my $mform = CXGN::Search::CannedForms::MarkerSearch->new($dbh);
144 $c->stash->{content} =
145 '<form action="/search/markers/markersearch.pl">'
146 . $mform->to_html()
147 . '</form>';
151 sub bac_search : Path('/search/genomic/clones') Args(0) {
152 $_[1]->stash->{content} = CXGN::Search::CannedForms->clone_search_form();
155 sub directory_search : Path('/search/directory') Args(0) {
156 $_[1]->stash->{content} = CXGN::Search::CannedForms->people_search_form();
159 #sub gene_search : Path('/search/loci') Args(0) {
160 # $_[1]->stash->{content} = CXGN::Search::CannedForms->gene_search_form();
163 sub images_search : Path('/search/images') Args(0) {
164 $_[1]->stash->{content} = CXGN::Search::CannedForms->image_search_form();
168 =head1 AUTHOR
170 Converted to Catalyst by Jonathan "Duke" Leto, then heavily refactored
171 by Robert Buels
173 =head1 LICENSE
175 This library is free software. You can redistribute it and/or modify
176 it under the same terms as Perl itself.
178 =cut
180 __PACKAGE__->meta->make_immutable;