Skip to content

Commit

Permalink
Added ref attr like search, search help box
Browse files Browse the repository at this point in the history
  • Loading branch information
lomky committed Feb 15, 2018
1 parent 26f560c commit 9627fe1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/Tuba/DB/Mixin/Object/Reference/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sub _make_query {

my @query;
# Search Attr:Value, leftovers as title
if ($str =~ /".*:.*"/){
if ($str =~ /".*[:~].*"/){
my @attr_pairs = split /", */, $str;
foreach my $attr_pair (@attr_pairs) {
$attr_pair =~ s/"//g;
Expand All @@ -22,8 +22,14 @@ sub _make_query {
$value = $dbh->quote($value);
push @query, \(qq[attrs->$key = $value ]);
}
elsif ( $attr_pair =~ /~/ ) {
my ($key,$value) = split /~/, $attr_pair;
$key = $dbh->quote($key);
$value = $dbh->quote('%'.$value.'%');
push @query, \(qq[attrs->$key ilike $value ]);
}
else {
$attr_pair = $dbh->quote($attr_pair);
$attr_pair = $dbh->quote('%'.$attr_pair.'%');
push @query, \(qq[attrs->'Title' ilike $attr_pair ]);
}
}
Expand Down
42 changes: 41 additions & 1 deletion lib/Tuba/files/templates/search/keyword.html.ep
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
% layout 'default';

<style>
.help {
display: inline-block;
position: relative;
}

.info-box {
width: 400px;
position: absolute;
right: -600px;
background-color: #F8F8F8;
}
</style>
<script>
jQuery(document).ready(function($){
$('.help-button').on('click', function(e){
e.preventDefault();
$(this).siblings('.info-box').show();
});

$('.close-button').on('click', function(e){
e.preventDefault();
$(this).parents('.info-box').hide();
});
});
</script>
%= form_for 'search' => class => "form form-inline well" => begin
<label>Search for </label>
%= text_field 'q', class => "form-control"
<label> in</label>
%= select_field 'type' => [ 'all', sort ('organization','person', db_identifiers('publication_type'))];
%= select_field 'type' => [ 'all', sort ('organization','person', db_identifiers('publication_type'), 'reference')];
and show
%= select_field 'format' => [ 'detailed', 'brief'];
match results.
<div class="help">
<div class="info-box" style="display: none;">
<a href="#" class="close-button">&times;</a>
<b>Search Information</b>
<ul>
<li>Regular searches look for matching identifiers and other key fields.</li>
<li>Reference Search</li>
<ul>
<li>Searching '"Year:2002", "Author:NRC" Word foo' will attempt to find a Reference with exact attribute Year 2002, exact attribute Author NRC, and Title like 'Word foo'.</li>
<li> Replacing the ':' with '~' in the previous query searches for like instead of exact. ("Year~200" searches Year ilike %200%)</li>
</ul>
</div>
<a class='help-button' href='#' title="Click to know more">[?]</a>
</div>
%= submit_button 'search', class => "btn btn-search btn-primary"
%= end

Expand Down

0 comments on commit 9627fe1

Please sign in to comment.