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