Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run-lane annotations to a search #815

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/npg/model/search.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#########
# Author: rmp
# Created: 2008-01
#
package npg::model::search;
use strict;
use warnings;
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -492,7 +498,7 @@ Roger Pettett, E<lt>[email protected]<gt>

=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,
Expand Down
33 changes: 24 additions & 9 deletions t/10-model-search.t
Original file line number Diff line number Diff line change
@@ -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');
}

{
Expand Down
46 changes: 14 additions & 32 deletions t/20-view-search.t
Original file line number Diff line number Diff line change
@@ -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;
Loading