better support for ranking and OpenILL integration
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Jun 2005 22:45:21 +0000 (22:45 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Jun 2005 22:45:21 +0000 (22:45 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@799 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/opensearch.pm
Open-ILS/src/extras/opensearch.ttk
Open-ILS/src/extras/opensearch.xml

index 63864b2..0ec38ab 100644 (file)
@@ -9,6 +9,7 @@ use APR::Const    -compile => qw(:error SUCCESS);
 use Apache::RequestRec ();
 use Apache::RequestIO ();
 use Apache::RequestUtil;
+use LWP::UserAgent;
 
 use CGI ();
 use Template qw(:template);
@@ -21,36 +22,42 @@ sub handler {
        my $apache = shift;
        print "Content-type: text/xml; charset=utf-8\n\n";
 
-       my $template = Template->new( { 
-               OUTPUT                  => $apache, 
-               ABSOLUTE                        => 1, 
-               RELATIVE                        => 1,
-               PLUGIN_BASE             => 'OpenILS::Template::Plugin',
-               INCLUDE_PATH    => ['/pines/cvs/ILS/Open-ILS/src/extras'], 
-               PRE_CHOMP               => 1,
-               POST_CHOMP              => 1,
-               } 
-       );
+       my $cgi = new CGI;
+       
+       if (my $fetch = $cgi->param('fetch')) {
 
-       try {
+               print LWP::UserAgent->new->get($fetch)->content;
 
-               if( ! $template->process( 'opensearch.ttk' ) ) { 
-                       warn "Error processing template opensearch.ttk\n";      
-                       warn  "Error Occured: " . $template->error();
-                       my $err = $template->error();
-                       $err =~ s/\n/\<br\/\>/g;
-                       print "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
-               }
-
-       } catch Error with {
-               my $e = shift;
-               warn "Error processing template opensearch.ttk:  $e - $@ \n";   
-               print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
-               return;
-       };
+       } else {
 
+               my $template = Template->new( { 
+                       OUTPUT                  => $apache, 
+                       ABSOLUTE                        => 1, 
+                       RELATIVE                        => 1,
+                       PLUGIN_BASE             => 'OpenILS::Template::Plugin',
+                       INCLUDE_PATH    => ['/pines/cvs/ILS/Open-ILS/src/extras'], 
+                       PRE_CHOMP               => 1,
+                       POST_CHOMP              => 1,
+                       } 
+               );
 
+               try {
+       
+                       if( ! $template->process( 'opensearch.ttk' ) ) { 
+                               warn "Error processing template opensearch.ttk\n";      
+                               warn  "Error Occured: " . $template->error();
+                               my $err = $template->error();
+                               $err =~ s/\n/\<br\/\>/g;
+                               print "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
+                       }
 
+               } catch Error with {
+                       my $e = shift;
+                       warn "Error processing template opensearch.ttk:  $e - $@ \n";   
+                       print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
+                       return;
+               };
+       }
        return Apache::OK;
 }
 
index 5be64ef..6aa7f7a 100644 (file)
@@ -24,8 +24,9 @@ type = CGI.param('mr_search_type');
 string = CGI.param('mr_search_query');
 location = CGI.param('mr_search_location');
 depth = CGI.param('mr_search_depth');
+max_rank = CGI.param('max_rank');
 limit = pagesize;
-offset = ((itempage - 1) * pagesize) - 1;
+offset = (itempage - 1) * pagesize;
 
 IF offset < 0;
        offset = 0;
@@ -42,20 +43,25 @@ j = id_req.wait_complete();
 list = id_req.recv().content();
 j = id_req.finish;
 
-max_rank = 0;
+IF max_rank == '{relevanceScale}';
+       max_rank = 0;
+END;
 
 -%]
 <?xml version="1.0"?>
-<rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
+<rss version="2.0"
+       xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
+       xmlns:openIll="http://open-ils.org/xml/openIll/1.0">
     <channel>
       <title>Pines Catalogue Search: [% string | html %] </title>
-      <link>http://http://gapines.org/opensearch/?target=mr_result&amp;mr_search_type=[% type %]&amp;mr_search_query=[% string | uri | html %]&amp;page=[% itempage %]&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]</link>
+      <link>http://http://gapines.org/opensearch/?target=mr_result&amp;mr_search_type=[% type %]&amp;mr_search_query=[% string | uri | html %]&amp;page=[% itempage %]&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]&amp;pagesize=[% pagesize %]&amp;max_rank=[% max_rank %]</link>
       <description>Search results for "[% string | html %]" at gapines.org</description>
       <language>en-us</language>
       <copyright>&amp;copy;2004-2005, Georga Public Library Service.</copyright>
       <openSearch:totalResults>[% count %]</openSearch:totalResults>
       <openSearch:startIndex>[% offset + 1 %]</openSearch:startIndex>
       <openSearch:itemsPerPage>[% pagesize %]</openSearch:itemsPerPage>
+
 [%-
 
 mr_list = list.ids;
@@ -66,6 +72,7 @@ FOREACH mr_id IN mr_list;
 
        IF max_rank == 0;
                max_rank = mr_id.1;
+               '      <openIll:relevanceScale>' _ max_rank _ "</openIll:relevanceScale>\n";
        END;
 
        rank = mr_id.1 / max_rank;
@@ -79,7 +86,7 @@ FOREACH mr_id IN mr_list;
       <item>
         <title>[% mods.title() | html %]</title>
         <link>http://gapines.org/opac/?sub_frame=1&amp;target=record_result&amp;page=0&amp;mrid=[% mr_id.0 %]&amp;hits_per_page=10</link>
-        <rank>[% rank %]</rank>
+        <openIll:relevance>[% rank %]</openIll:relevance>
         <description>
 [%-
        IF mods.author();
index 9fa0dfa..9f5edff 100644 (file)
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
-  <Url>http://gapines.org/opensearch/?target=mr_result&amp;mr_search_type=keyword&amp;mr_search_query={searchTerms}&amp;page={startPage}&amp;mr_search_depth=0&amp;mr_search_location=1</Url>
+<OpenSearchDescription
+       xmlns="http://a9.com/-/spec/opensearchdescription/1.0/"
+       xmlns:openIll="http://open-ils.org/xml/openIll/1.0">
+  <Url>http://gapines.org/opensearch/?target=mr_result&amp;mr_search_type=keyword&amp;mr_search_query={searchTerms}&amp;page={startPage}&amp;mr_search_depth=0&amp;mr_search_location=1&amp;pagesize={count}&amp;max_rank={relevanceScale}</Url>
   <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
   <ShortName>Pines</ShortName>
   <LongName>Pines Consortium Catalogue</LongName>