From 504b684a884bc71914c28630aec1e4fbe8c862ab Mon Sep 17 00:00:00 2001 From: Marina Gourtovaia Date: Tue, 19 Mar 2024 13:58:20 +0000 Subject: [PATCH] Add run-lane annotations to a search --- lib/npg/model/search.pm | 18 ++++++++++------ t/10-model-search.t | 33 +++++++++++++++++++++-------- t/20-view-search.t | 46 +++++++++++++---------------------------- 3 files changed, 50 insertions(+), 47 deletions(-) diff --git a/lib/npg/model/search.pm b/lib/npg/model/search.pm index 8425ec64..86fb9818 100644 --- a/lib/npg/model/search.pm +++ b/lib/npg/model/search.pm @@ -1,7 +1,3 @@ -######### -# Author: rmp -# Created: 2008-01 -# package npg::model::search; use strict; use warnings; @@ -77,7 +73,7 @@ sub results { AND content LIKE ?), "%$term%"]; ######### - # search run annotations + # search annotations # push @{$queries}, [q(SELECT 'run' AS type, ra.id_run AS primary_key, @@ -89,6 +85,16 @@ sub results { AND a.comment LIKE ? ORDER BY date DESC LIMIT 100), "%$term%"]; + push @{$queries}, [q(SELECT 'run_lane' AS type, + rla.id_run_lane AS primary_key, + 'annotation' AS location, + a.comment AS context + FROM annotation a, + run_lane_annotation rla + WHERE rla.id_annotation = a.id_annotation + AND a.comment LIKE ? + ORDER BY date DESC + LIMIT 100), "%$term%"]; ######### # search instrument annotations & statuses @@ -492,7 +498,7 @@ Roger Pettett, Ermp@sanger.ac.ukE =head1 LICENSE AND COPYRIGHT -Copyright (C) 2007 GRL, by Roger Pettett +Copyright (C) 2007, 2013, 2014, 2017, 2024 Genome Research Ltd. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, diff --git a/t/10-model-search.t b/t/10-model-search.t index 44add79b..b1bcf09b 100644 --- a/t/10-model-search.t +++ b/t/10-model-search.t @@ -1,22 +1,37 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 13; +use List::MoreUtils qw/uniq/; use t::util; use_ok('npg::model::search'); -my $util = t::util->new({ - fixtures => 1, - }); +my $util = t::util->new({fixtures => 1,}); { - my $search = npg::model::search->new({ - util => $util, - }); + my $search = npg::model::search->new({util => $util,}); - $search->query('Lack of clusters'); + my $query = 'Lack of clusters'; + $search->query($query); my $results = $search->results(); - is((scalar @{$results}), 1, 'exact run annotation'); + is((scalar @{$results}), 2, 'run and run-lane annotations'); + is($results->[0]->[0], 'run', 'run annotation first'); + is($results->[1]->[0], 'run_lane', 'run-lane annotation second'); + my @annotations = uniq map { $_->[3] } @{$results}; + ok((@annotations == 1) && ($annotations[0] eq "${query} - run cancelled"), + 'correct annotations are retrieved'); + + $query = 'Training flow'; + $search->query($query); + $results = $search->results(); + is((scalar @{$results}), 7, 'run and run-lane annotations'); + my $n = grep { $_->[0] eq 'run' } @{$results}; + is($n, 3, 'three run annotation'); + $n = grep { $_->[0] eq 'run_lane' } @{$results}; + is($n, 4, 'four run-lane annotation'); + @annotations = uniq map { $_->[3] } @{$results}; + ok((@annotations == 1) && ($annotations[0] eq 'Training Flowcell'), + 'correct annotations are retrieved'); } { diff --git a/t/20-view-search.t b/t/20-view-search.t index d5f201b2..ca574338 100644 --- a/t/20-view-search.t +++ b/t/20-view-search.t @@ -1,53 +1,35 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 3; use t::util; use t::request; use npg::model::search; use_ok('npg::view::search'); -my $util = t::util->new({ - fixtures => 1, - }); +my $util = t::util->new({fixtures => 1,}); { my $str = t::request->new({ - PATH_INFO => '/search', - REQUEST_METHOD => 'GET', + PATH_INFO => '/search', + REQUEST_METHOD => 'GET', username => 'public', - util => $util, - cgi_params => { - query => 'TriosP', - }, - }); + util => $util, + cgi_params => {query => 'TriosP',}, + }); ok($util->test_rendered($str, 't/data/rendered/search.html'), 'list render'); } { my $str = t::request->new({ - PATH_INFO => '/search', - REQUEST_METHOD => 'GET', + PATH_INFO => '/search', + REQUEST_METHOD => 'GET', username => 'public', - util => $util, - cgi_params => { - query => ' TriosP', - }, - }); - ok($util->test_rendered($str, 't/data/rendered/search.html'), 'list render leading whitespace'); -} - -{ - my $str = t::request->new({ - PATH_INFO => '/search', - REQUEST_METHOD => 'GET', - username => 'public', - util => $util, - cgi_params => { - query => 'TriosP ', - }, - }); - ok($util->test_rendered($str, 't/data/rendered/search.html'), 'list render trailing whitespace'); + util => $util, + cgi_params => {query => ' TriosP ',}, + }); + ok($util->test_rendered($str, 't/data/rendered/search.html'), + 'list render leading and trailing whitespace'); } 1;