From 2f59fd62eb8e444af505e193a9f5f7c77011f7a2 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Wed, 14 Dec 2016 11:40:34 -0800 Subject: [PATCH] add search_by_file option --- bibtex_to_paper | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bibtex_to_paper b/bibtex_to_paper index d5c6bb1..77cbffa 100755 --- a/bibtex_to_paper +++ b/bibtex_to_paper @@ -91,6 +91,7 @@ my %options = (debug => 0, man => 0, only_print => 0, search_by_pmid => 0, + search_by_file => 0, use_git => 1, 'bibtex_cache' => File::Spec->catfile(User->Home,'.bibtex_to_paper_cache'), ); @@ -103,6 +104,7 @@ GetOptions(\%options, 'use_git|use-git!', 'only_print|only-print!', 'search_by_pmid|search-by-pmid!', + 'search_by_file|search-by-file!', 'clear_cache|clear-cache!', 'papers_directory|papers-directory=s@', 'debug|d+','help|h|?','man|m'); @@ -236,6 +238,8 @@ sub open_bibtex_key { my $entry; if ($options->{search_by_pmid}) { $entry = select_entry_from_pmid($dbh,$sth,$bibtex_key); + } elsif ($options->{search_by_file}) { + $entry = select_entry_from_file($dbh,$sth,$bibtex_key); } else { $entry = select_entry_from_bibtex_key($dbh,$sth,$bibtex_key); } @@ -333,6 +337,12 @@ sub select_entry_from_pmid{ return select_one($dbh,$sth->{select_bibtex_by_pmid},$pmid); } +sub select_entry_from_file{ + my ($dbh,$sth,$filename) = @_; + + return select_one($dbh,$sth->{select_bibtex_by_file_name_like},'%'.$filename.'%'); +} + sub select_entry_from_bibtex_key{ my ($dbh,$sth,$bibtex_key) = @_; @@ -468,7 +478,7 @@ EOF select_papers_by_name => <<'EOF', SELECT * FROM papers WHERE file_name = ?; EOF - select_papers_by_pmid => <<'EOF', + select_papers_by_name_like => <<'EOF', SELECT * FROM papers WHERE file_name LIKE ?; EOF select_papers_by_path => <<'EOF', @@ -482,6 +492,9 @@ SELECT * FROM bibtex WHERE bibtex_key LIKE ?; EOF select_bibtex_by_file_name => <<'EOF', SELECT * FROM bibtex WHERE file_name = ?; +EOF + select_bibtex_by_file_name_like => <<'EOF', +SELECT * FROM bibtex WHERE file_name LIKE ?; EOF select_bibtex_by_pmid => <<'EOF', SELECT * FROM bibtex WHERE pmid = ?; -- 2.39.2