bug fixes after testing
[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('page');
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 max_rank = CGI.param('max_rank');
28 limit = pagesize;
29 offset = (itempage - 1) * pagesize;
30
31 IF offset < 0;
32         offset = 0;
33 END;
34
35 count_req = session.request(count_meth, type, string, location, depth);
36 id_req = session.request(search_meth, type, string, location, depth, limit, offset);
37
38 j = count_req.wait_complete();
39 count = count_req.recv().content();
40 j = count_req.finish;
41
42 j = id_req.wait_complete();
43 list = id_req.recv().content();
44 j = id_req.finish;
45
46 IF max_rank == '{relevanceScale}';
47         max_rank = 0;
48 END;
49
50 -%]
51 <?xml version="1.0"?>
52 <rss version="2.0"
53         xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
54         xmlns:openIll="http://open-ils.org/xml/openIll/1.0">
55     <channel>
56       <title>Pines Catalogue Search: [% string | html %] </title>
57       <link>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>
58       <description>Search results for "[% string | html %]" at gapines.org</description>
59       <language>en-us</language>
60       <copyright>&amp;copy;2004-2005, Georga Public Library Service.</copyright>
61       <openSearch:totalResults>[% count %]</openSearch:totalResults>
62       <openSearch:startIndex>[% offset + 1 %]</openSearch:startIndex>
63       <openSearch:itemsPerPage>[% pagesize %]</openSearch:itemsPerPage>
64
65 [%-
66
67 mr_list = list.ids;
68
69 FOREACH mr_id IN mr_list;
70         req = session.request('open-ils.search.biblio.metarecord.mods_slim.retrieve', mr_id.0);
71         j = req.wait_complete();
72
73         IF max_rank == 0;
74                 max_rank = mr_id.1;
75         END;
76         '      <openIll:relevanceScale>' _ max_rank _ "</openIll:relevanceScale>\n";
77
78         rank = mr_id.1 / max_rank;
79         rank = rank * 100;
80         rank = rank.split('\.').0;
81
82         mods = req.recv().content();
83         j = req.finish;
84
85 -%]
86       <item>
87         <title>[% mods.title() | html %]</title>
88         <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>
89         <openIll:relevance>[% rank %]</openIll:relevance>
90         <description>
91 [%-
92         IF mods.isbn();
93 -%]
94                 &lt;div style="float: left;"&gt;
95                         &lt;a href="http://gapines.org/opac/?sub_frame=1&amp;target=record_result&amp;page=0&amp;mrid=[% mr_id.0 %]&amp;hits_per_page=10"&gt;
96                                 &lt;img
97                                         style="padding: 3px; border: none;"
98                                         width="45"
99                                         height="50"
100                                         src="http://images.amazon.com/images/P/[% mods.isbn().replace('\s+','') %].01.MZZZZZZZ.jpg"&gt;
101                         &lt;/a&gt;
102                 &lt;/div&gt;
103 [%-
104         END;
105         IF mods.author();
106 -%]
107                 &lt;b&gt;Author:&lt;/b&gt; &lt;a href="http://gapines.org/opac/?sub_frame=1&amp;target=mr_result&amp;mr_search_type=author&amp;mr_search_query=[% mods.author() | uri | html %]&amp;page=0&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]"&gt;[% mods.author() | html %]&lt;/a&gt;&lt;br&gt;
108 [%
109         END;
110         IF mods.subject();
111 %]
112                 &lt;b&gt;Subjects:&lt;/b&gt; 
113 [%
114         FOREACH sub IN mods.subject().keys;
115                 IF loop.count() > 3;
116                         ', ...';
117                         LAST;
118                 END;
119                 IF loop.index;
120                         ', ';
121                 END;
122                 -%]
123 &lt;a href="http://gapines.org/opac/?sub_frame=1&amp;target=mr_result&amp;mr_search_type=subject&amp;mr_search_query=[% sub | uri | html %]&amp;page=0&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]"&gt;[% sub | html %]&lt;/a&gt;[%
124         END;
125 %]
126 &lt;br&gt;
127
128 [%
129         l = mods.online_loc();
130         IF l.size;
131                 '&lt;b&gt;Other Resources:&lt;/b&gt;';
132         x = l.size / 2;
133                 i = 0;
134                 saw = { 'no' => 'no' };
135 %][%
136                 WHILE i <= x;
137
138                         h = i * 2;
139                         t = h + 1;
140         
141                         h = l.list.$h | uri | html;
142                         t = l.list.$t | html;
143
144 %][%
145                         IF saw.exists(t);
146                                 i = i + 1;
147                                 NEXT;
148                         END
149
150 %][%
151                         saw.$t = t;
152                         
153                         '&lt;a href="' _ h _ '"&gt;' _ t _ '&lt;/a&gt;&amp;nbsp;';
154         
155                         i = i + 1;
156                 END;
157                 '&lt;br&gt;';
158         END; 
159
160         END;
161 %]
162                 &lt;b&gt;Copies Available:&lt;/b&gt; [% mr_id.2 %] 
163         </description>
164       </item>
165 [%-
166
167 END;
168
169  -%]
170   </channel>
171 </rss>