]> git.donarmstrong.com Git - bin.git/commitdiff
add search_by_file option
authorDon Armstrong <don@donarmstrong.com>
Wed, 14 Dec 2016 19:40:34 +0000 (11:40 -0800)
committerDon Armstrong <don@donarmstrong.com>
Wed, 14 Dec 2016 19:40:34 +0000 (11:40 -0800)
bibtex_to_paper

index d5c6bb1e37c7fb638adcbd0db64783ca43c97f90..77cbffaba17091b288982783821d4567f6935bed 100755 (executable)
@@ -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 = ?;