]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/opensearch.ttk
bugfix
[Evergreen.git] / Open-ILS / src / extras / opensearch.ttk
1 [%-
2 USE CGI;
3 USE ws = WebSession;
4 j = ws.bootstrap_client("/pines/conf/bootstrap.conf");
5
6 rank_threshold = 5000;
7
8 itempage = CGI.param('itempage');
9
10 #type,string,location,depth
11 count_meth = 'open-ils.search.biblio.class.count';
12
13 #type,string,location,depth,limit,offset
14 search_meth = 'open-ils.search.biblio.class';
15
16 session = ws.init_app_session('open-ils.search');
17
18 type = CGI.param('mr_search_type');
19 string = CGI.param('mr_search_query');
20 location = CGI.param('mr_search_location');
21 depth = CGI.param('mr_search_depth');
22 limit = pagesize;
23 offset = itempage * pagesize - 1;
24
25 pagesize = 10;
26 IF CGI.param('pagesize');
27         pagesize = CGI.param('pagesize');
28 END;
29
30 req = session.request(count_meth, type, string, location, depth);
31 j = req.wait_complete();
32
33 count = req.recv().content();
34 j = req.finish;
35
36 IF count > rank_threshold;
37         search_meth = 'open-ils.search.biblio.class.unordered';
38 END;
39
40 req = session.request(search_meth, type, string, location, depth, limit, offset);
41 j = req.wait_complete();
42
43 list = req.recv().content();
44 j = req.finish;
45
46 -%]
47 <?xml version="1.0"?>
48 <rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
49     <channel>
50       <title>Pines Catalogue Search: [% string %] </title>
51       <link>http://http://gapines.org/opensearch/?target=mr_result&amp;mr_search_type=[% type %]&amp;mr_search_query=[% string %]&amp;itempage=[% itempage %]&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]</link>
52       <description>Search results for "[% string %]" at gapines.org</description>
53       <language>en-us</language>
54       <copyright>&amp;copy;2004-2005, Georga Public Library Service.</copyright>
55       <openSearch:totalResults>[% count %]</openSearch:totalResults>
56       <openSearch:startIndex>[% offset + 1 %]</openSearch:startIndex>
57       <openSearch:itemsPerPage>[% pagesize %]</openSearch:itemsPerPage>
58 [%-
59
60 mr_list = list.id;
61
62 FOREACH mr_id IN mr_list;
63         req = session.request('open-ils.search.biblio.metarecord.mods_slim.retrieve', mr_id.0);
64         req.wait_complete();
65
66         mods = req.recv().content();
67         req.finish;
68
69 -%]
70       <item>
71         <title>[% mods.title() %]</title>
72         <link>http://gapines.org/opac/?target=record_result&page=0&mrid=[% mr_id.0 %]&hits_per_page=10</link>
73         <description>
74                 &lt;b&gt;Author:&lt;/b&gt; [% mods.author() %]&lt;br&gt;
75                 &lt;b&gt;Subjects:&lt;/b&gt; 
76 [%-
77         FOREACH sub IN mods.subject();
78                 IF loop.count() > 5;
79                         ', ...';
80                         LAST;
81                 END;
82                 IF loop.index;
83                         ', ';
84                 END;
85                 sub.list.0;
86         END;
87 -%]
88                 &lt;b&gt;Available:&lt;/b&gt; [% mr_id.2 %] 
89         </description>
90       </item>
91 [%-
92
93 END;
94
95  -%]
96   </channel>
97 </rss>