[LON-CAPA-cvs] cvs: modules /gerd/harvesting recomprocs.pl /gerd/harvesting/dbfiles keywords.pl

www www at source.lon-capa.org
Sun Jun 24 20:29:03 EDT 2012


www		Mon Jun 25 00:29:03 2012 EDT

  Added files:                 
    /modules/gerd/harvesting/dbfiles	keywords.pl 

  Modified files:              
    /modules/gerd/harvesting	recomprocs.pl 
  Log:
  Keyword search
  
  
Index: modules/gerd/harvesting/recomprocs.pl
diff -u modules/gerd/harvesting/recomprocs.pl:1.2 modules/gerd/harvesting/recomprocs.pl:1.3
--- modules/gerd/harvesting/recomprocs.pl:1.2	Sun Jun 24 23:07:39 2012
+++ modules/gerd/harvesting/recomprocs.pl	Mon Jun 25 00:29:03 2012
@@ -151,10 +151,40 @@
    return %output;
 }
 
+# =================================================================================
+#
+#  Return the resource keys that match the keywords
+#
+
+sub keyword_search {
+   my @keywords=@_;
+   my %output=();
+   my $skey=join(',', at keywords);
+   $skey=~s/^\W+//gs;
+   $skey=~s/\W+$//gs;
+   $skey=~s/\W+/\|/gs;
+   $skey=lc($skey);
+   my $pattern=qr/$skey/;
+   my %hash;
+   tie(%hash, 'GDBM_File', $datapath.'dbfiles/keywords.db',&GDBM_READER(),0640);
+   foreach my $key (keys(%hash)) {
+      if ($hash{$key}=~$pattern) {
+         $output{$key}=1;
+      }
+   }
+   untie(%hash);
+   return(%output);
+}
+
+
+
+# Testing below
+
 my $parm=shift;
 print "Parameter: $parm\n";
 #my %stuff=&associated(split(/\s*\,\s*/,$parm));
-my %stuff=&taxonomy_members(split(/\s*\,\s*/,$parm));
+#my %stuff=&taxonomy_members(split(/\s*\,\s*/,$parm));
+my %stuff=&keyword_search($parm);
 #foreach my $key (keys(%stuff)) {
 #    print $key." ".$stuff{$key}."\n";
 #}

Index: modules/gerd/harvesting/dbfiles/keywords.pl
+++ modules/gerd/harvesting/dbfiles/keywords.pl
use GDBM_File;
my $skey=shift;
$skey=~s/^\W+//gs;
$skey=~s/\W+$//gs;
$skey=~s/\W+/\|/gs;
$skey=lc($skey);
print "Looking for $skey\n";
my $pattern=qr/$skey/;
my %hash;
tie(%hash, 'GDBM_File','keywords.db',&GDBM_READER(),0640);
foreach my $key (keys(%hash)) {
    if ($hash{$key}=~$pattern) {
       print "[".$key."]\t".$hash{$key}."\n";
    }
}
untie(%hash);




More information about the LON-CAPA-cvs mailing list