2 package SMMID
::Controller
::Search
;
7 use SMMID
::Authentication
::ViewPermission
;
9 BEGIN { extends
'Catalyst::Controller'; }
11 sub search
: Path
('/search') Args
(0) {
15 $c->stash->{template
} = '/search.mas';
18 sub search_results
:Path
('/search/results') Args
(0) {
22 my $search_term = $c->req->param("term");
23 my $smid_id = $c->req->param("smid_id");
24 my $formula = $c->req->param("formula");
25 my $retention_time = $c->req->param("retention_time");
26 my $retention_time_range = $c->req->param("retention_time_range");
27 my $molecular_weight = $c->req->param("molecular_weight");
28 my $molecular_weight_range = $c->req->param("molecular_weight_range") || 0;
29 my $smiles = $c->req->param('smiles');
32 if ($search_term) { # simple search
33 print STDERR
"Searching simple search with search term '$search_term'\n";
34 $rs = $c->model('SMIDDB')->resultset("SMIDDB::Result::Compound")->search( { -or => [ smid_id
=> { ilike
=> '%'.$search_term.'%' }, formula
=> { ilike
=> '%'.$search_term.'%'}, smiles
=> { ilike
=> '%'.$search_term.'%' } ] } );
38 print STDERR
"Complex search...\n";
39 $rs = $c->model('SMIDDB')->resultset("SMIDDB::Result::Compound")->search( {}, { join => 'experiments'} );
41 print STDERR
"Currently matched ".$rs->count()." smids...\n";
44 $rs = $rs->search( { smid_id
=> { ilike
=> '%'.$smid_id.'%' }} );
45 print STDERR
"With parameter smid_id = $smid_id matched ".$rs->count()." smids...\n";
49 $rs = $rs->search( { formula
=> { ilike
=> '%'.$formula.'%'} });
50 print STDERR
"Currently matched ".$rs->count()." smids...\n";
54 $rs = $rs->search( { smiles
=> { ilike
=> '%'.$smiles.'%' } });
55 print STDERR
"Currently matched ".$rs->count()." smids...\n";
59 if ($molecular_weight) {
61 { -and => [ molecular_weight
=> { '>' => ($molecular_weight - $molecular_weight_range) },
62 molecular_weight
=> { '<' => ($molecular_weight + $molecular_weight_range) } ] } );
63 print STDERR
"after MW currently matched ".$rs->count()." smids...\n";
66 if ($retention_time) {
73 while (my $row = $rs->next()) {
74 next if (!SMMID
::Authentication
::ViewPermission
::can_view_smid
($c->user(), $row, $c->model("SMIDDB")));
75 my $compound_id = $row->compound_id();
76 my $smid_id = $row->smid_id();
77 my $formula = $row->formula();
78 my $smiles = $row->smiles();
80 my $smid_link = '<a href=\"/smid/'.$compound_id.'\">'.$smid_id."</a>";
81 push @results, [ $smid_link, $formula, $smiles ];
86 #print STDERR Dumper(\@results);
88 $c->stash->{data
} = encode_json
(\
@results);
90 #print STDERR "JSON: ".$c->stash->{data}."\n";
92 $c->stash->{template
} = '/search/results.mas';