]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/opensearch.ttk
mike stuff + fieldmapper for web stuff
[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 limit = pagesize;
28 offset = ((itempage - 1) * pagesize) - 1;
29
30 IF offset < 0;
31         offset = 0;
32 END;
33
34 count_req = session.request(count_meth, type, string, location, depth);
35 id_req = session.request(search_meth, type, string, location, depth, limit, offset);
36
37 j = count_req.wait_complete();
38 count = count_req.recv().content();
39 j = count_req.finish;
40
41 j = id_req.wait_complete();
42 list = id_req.recv().content();
43 j = id_req.finish;
44
45 max_rank = 0;
46
47 -%]
48 <?xml version="1.0"?>
49 <rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
50     <channel>
51       <title>Pines Catalogue Search: [% string | html %] </title>
52       <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>
53       <description>Search results for "[% string | html %]" at gapines.org</description>
54       <language>en-us</language>
55       <copyright>&amp;copy;2004-2005, Georga Public Library Service.</copyright>
56       <openSearch:totalResults>[% count %]</openSearch:totalResults>
57       <openSearch:startIndex>[% offset + 1 %]</openSearch:startIndex>
58       <openSearch:itemsPerPage>[% pagesize %]</openSearch:itemsPerPage>
59 [%-
60
61 mr_list = list.ids;
62
63 FOREACH mr_id IN mr_list;
64         req = session.request('open-ils.search.biblio.metarecord.mods_slim.retrieve', mr_id.0);
65         j = req.wait_complete();
66
67         IF max_rank == 0;
68                 max_rank = mr_id.1;
69         END;
70
71         rank = mr_id.1 / max_rank;
72         rank = rank * 100;
73         rank = rank.split('\.').0;
74
75         mods = req.recv().content();
76         j = req.finish;
77
78 -%]
79       <item>
80         <title>[% mods.title() | html %]</title>
81         <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>
82         <rank>[% rank %]</rank>
83         <description>
84 [%-
85         IF mods.author();
86 -%]
87                 &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;
88 [%-
89         END;
90         IF mods.subject();
91 -%]
92                 &lt;b&gt;Subjects:&lt;/b&gt; 
93 [%-
94         FOREACH sub IN mods.subject();
95                 IF loop.count() > 3;
96                         ', ...';
97                         LAST;
98                 END;
99                 IF loop.index;
100                         ', ';
101                 END;
102                 -%]&lt;a href="http://gapines.org/opac/?sub_frame=1&amp;target=mr_result&amp;mr_search_type=subject&amp;mr_search_query=[% sub.list.0 | uri | html %]&amp;page=0&amp;mr_search_depth=[% depth %]&amp;mr_search_location=[% location %]"&gt;[% sub.list.0 | html %]&lt;/a&gt;[%-
103         END;
104 -%]&lt;br&gt;
105 [%-
106         END;
107 -%]
108                 &lt;b&gt;Copies Available:&lt;/b&gt; [% mr_id.2 %] 
109         </description>
110       </item>
111 [%-
112
113 END;
114
115  -%]
116   </channel>
117 </rss>