LP1054322 - libparent-perl not needed for Ubuntu Precise
[working/Evergreen.git] / Open-ILS / src / extras / opensearch.ttk
1 [%-
2 USE CGI;
3 USE ws = WebSession;
4 j = ws.bootstrap_client("/openils/conf/opensrf_core.xml");
5
6 rank_threshold = 5000;
7 base_url = 'http://dev.gapines.org/';
8
9 pagesize = 10;
10 IF CGI.param('pagesize');
11         pagesize = CGI.param('pagesize');
12 END;
13
14 itempage = CGI.param('page');
15
16 #type,string,location,depth,limit,offset
17 search_meth = 'open-ils.search.biblio.class';
18
19 session = ws.init_app_session('open-ils.search');
20
21 type = CGI.param('mr_search_type');
22 string = CGI.param('mr_search_query');
23 location = CGI.param('mr_search_location');
24 depth = CGI.param('mr_search_depth');
25 max_rank = CGI.param('max_rank') || 0;
26 limit = pagesize;
27 offset = (itempage - 1) * pagesize;
28
29 IF offset < 0;
30         offset = 0;
31 END;
32
33 id_req = session.request(search_meth, type, string, location, depth, limit, offset);
34
35 j = id_req.wait_complete();
36 list = id_req.recv().content();
37 j = id_req.finish;
38
39 count = list.count;
40
41 IF max_rank == '{relevanceScale}';
42         max_rank = 0;
43 END;
44
45 -%]
46 <?xml version="1.0"?>
47 <rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
48     <channel>
49       <title>Pines Catalogue Search: [% string | html %] </title>
50       <link>[% base_url %]/opac/extras/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>
51       <description>Search results for "[% string | html %]" at dev.gapines.org</description>
52       <language>en-us</language>
53       <copyright>&amp;copy;2004-2005, Georga Public Library Service.</copyright>
54       <openSearch:totalResults>[% count %]</openSearch:totalResults>
55       <openSearch:startIndex>[% offset + 1 %]</openSearch:startIndex>
56       <openSearch:itemsPerPage>[% pagesize %]</openSearch:itemsPerPage>
57
58 [%-
59
60 mr_list = list.ids;
61
62 FOREACH mr_id = mr_list;
63         req = session.request('open-ils.search.biblio.metarecord.mods_slim.retrieve', mr_id.0);
64         j = req.wait_complete();
65
66         IF max_rank == 0;
67                 max_rank = mr_id.1;
68                 '      <openSearch:relevanceScale>' _ max_rank _ "</openSearch:relevanceScale>\n";
69         END;
70
71         rank = mr_id.1 / max_rank;
72         rank = rank * 100;
73         rank = rank.split('\.').0;
74
75         #'<!-- Got a metarecord... ' _ mr_id.0 _ ' relevance: ' _ mr_id.1 _ ' rank: ' _ rank _ ' scale: ' _ max_rank _ '-->';
76
77         mods = req.recv().content();
78         j = req.finish;
79
80 -%]
81       <item>
82         <title>[% mods.title() | html %]</title>
83         <link>[% base_url %]/opac/en-US/skin/default/xml/rresult.xml?m=[% mr_id.0 %]&amp;l=[% location %]</link>
84         <openSearch:relevance>[% rank %]</openSearch:relevance>
85         <description>
86 [%-
87         IF mods.isbn();
88 -%]
89                 &lt;div style="float: left;"&gt;
90                         &lt;a href="[% base_url %]/opac/en-US/skin/default/xml/rresult.xml?m=[% mr_id.0 %]&amp;l=[% location %]"&gt;
91                                 &lt;img
92                                         style="padding: 3px; border: none;"
93                                         width="45"
94                                         height="50"
95                                         src="http://images.amazon.com/images/P/[% mods.isbn().split('\s+').0 %].01.MZZZZZZZ.jpg"&gt;
96                         &lt;/a&gt;
97                 &lt;/div&gt;
98 [%-
99         END;
100         IF mods.author();
101 -%]
102                 &lt;b&gt;Author:&lt;/b&gt; &lt;a href="[% base_url %]/opac/en-US/skin/default/xml/mresult.xml?tp=author&amp;t=[% mods.author() | uri | html %]&amp;l=[% location %]"&gt;[% mods.author() | html %]&lt;/a&gt;&lt;br&gt;
103 [%
104         END;
105         IF mods.subject();
106 %]
107                 &lt;b&gt;Subjects:&lt;/b&gt; 
108 [%
109         FOREACH sub IN mods.subject().keys;
110                 IF loop.count() > 3;
111                         ', ...';
112                         LAST;
113                 END;
114                 IF loop.index;
115                         ', ';
116                 END;
117                 -%]
118 &lt;a href="[% base_url %]/opac/en-US/skin/default/xml/mresult.xml?tp=subject&amp;mr_search_query=[% sub | uri | html %]"&gt;[% sub | html %]&lt;/a&gt;[%
119         END;
120 %]
121 &lt;br&gt;
122
123 [%
124         l = mods.online_loc();
125         IF l.size;
126                 '&lt;b&gt;Other Resources:&lt;/b&gt;';
127         x = l.size / 2;
128                 i = 0;
129                 saw = { 'no' => 'no' };
130 %][%
131                 WHILE i <= x;
132
133                         h = i * 2;
134                         t = h + 1;
135         
136                         h = l.list.$h | uri | html;
137                         t = l.list.$t | html;
138
139 %][%
140                         IF saw.exists(t);
141                                 i = i + 1;
142                                 NEXT;
143                         END
144
145 %][%
146                         saw.$t = t;
147                         
148                         '&lt;a href="' _ h _ '"&gt;' _ t _ '&lt;/a&gt;&amp;nbsp;';
149         
150                         i = i + 1;
151                 END;
152                 '&lt;br&gt;';
153         END; 
154
155         END;
156 %]
157         </description>
158       </item>
159 [%-
160
161 END;
162
163  -%]
164   </channel>
165 </rss>