[LON-CAPA-cvs] cvs: nsdl / lonsql

www lon-capa-cvs@mail.lon-capa.org
Thu, 24 Nov 2005 21:34:33 -0000


www		Thu Nov 24 16:34:33 2005 EDT

  Modified files:              
    /nsdl	lonsql 
  Log:
  NSDL Search: saving my work
  
  
Index: nsdl/lonsql
diff -u nsdl/lonsql:1.6 nsdl/lonsql:1.7
--- nsdl/lonsql:1.6	Thu Nov 24 15:21:15 2005
+++ nsdl/lonsql	Thu Nov 24 16:34:31 2005
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-NSDL Query Handler.
 #
-# $Id: lonsql,v 1.6 2005/11/24 20:21:15 www Exp $
+# $Id: lonsql,v 1.7 2005/11/24 21:34:31 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -404,7 +404,7 @@
                 }
             } else {
                 # Do an sql query
-                $result = &do_sql_query($query,$arg1,$arg2);
+                $result = &nsdl_query($query,$arg1,$arg2);
             }
             # result does not need to be escaped because it has already been
             # escaped.
@@ -420,58 +420,6 @@
         exit;
     }
 }
-
-########################################################
-########################################################
-
-=pod
-
-=item &do_sql_query
-
-Runs an sql metadata table query.
-
-Inputs: $query, $custom, $customshow
-
-Returns: A string containing escaped results.
-
-=cut
-
-########################################################
-########################################################
-{
-    my @metalist;
-
-sub process_file {
-    if ( -e $_ &&  # file exists
-         -f $_ &&  # and is a normal file
-         /\.meta$/ &&  # ends in meta
-         ! /^.+\.\d+\.[^\.]+\.meta$/  # is not a previous version
-         ) {
-        push(@metalist,$File::Find::name);
-    }
-}
-
-sub do_sql_query {
-    my ($query) = @_;
-#    &logthis('doing query '.$query);
- 
-    my @results = ();
- 
-    #
-    if ($query) {
-        #prepare and execute the query
-	my $aref=&nsdl_query($query);
-	foreach my $row (@$aref) {
-	    my @b=map { &escape($_); } @$row;
-	    push @results,join(",", @b);
-	}
-        
-    }
-    return join("&",@results);
-} # End of &do_sql_query
-
-} # End of scoping curly braces for &process_file and &do_sql_query
-########################################################
 ########################################################
 
 =pod
@@ -845,23 +793,21 @@
 #
 # Takes SQL query
 # sends it to NSDL
-# has to return array reference
 #
 
 sub nsdl_query {
     my $query=shift;
     my ($keyword)=($query=~/\"\%([^\%]+)\%\"/);
     $keyword=&escape($keyword);
-    &logthis('Doing '.$keyword);
     my $url='http://search.nsdl.org?verb=Search&s=0&n=500&q=-link.primaryCollection:oai\:nsdl.org\:nsdl.nsdl\:00254%20'.$keyword;
     my $ua=new LWP::UserAgent;
     my $response=$ua->get($url);
     my $parser=HTML::LCParser->new(\$response->content);
-    my %result=();
-    my $is=();
+    my $is='';
     my $cont='';
-    my $array=[];
     my $token;
+    my %result=();
+    my $allresults='';
     while ($token=$parser->get_token) {
 	if ($token->[0] eq 'T') {
 	    $cont.=$token->[1];
@@ -877,12 +823,25 @@
 #
 # Now store it away
 #
+                my $url=$result{'dc:identifier'};
+                if ($url=~/^http\:/) {
+                   $url=~s/^http:\//\/ext/;
+                } else {
+                   $url='';
+                }
+                $allresults.='&'.
+                    &escape($result{'dc:title'}).','.
+                    &escape($result{'dc:creator'}).','.
+                    &escape($url).','.
+                    &escape($result{'dc:subject'}).',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,';
 	    } elsif ($token->[1]=~/^dc\:/) {
 		$result{$is}=$cont;
 	    }
 	}
     }
-    return $array;
+    $allresults=~s/^\&//;
+&logthis($allresults);
+    return $allresults;
 }
 
 =pod