]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/extras/opensearch.ttk
initial opensearch implementation
[working/Evergreen.git] / Open-ILS / src / extras / opensearch.ttk
1 [%-
2 USE CGI;
3 USE WebSession;
4 WebSession.bootstrap();
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 = WebSession.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 req.wait_complete();
32
33 count = req.recv();
34 req.finish;
35
36 IF count > rank_threshold;
37         search_meth = 'open-ils.search.biblio.class.unorded';
38 END;
39
40 req = session.request(search_meth, type, string, location, depth, limit, offset);
41 req.wait_complete();
42
43 list = req.recv();
44 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.ttk/?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 FOREACH mr_id IN list;
61         req = session.request('open-ils.search.biblio.metarecord.mods_slim.retrieve', mr_id);
62         req.wait_complete();
63
64         mods = req.recv();
65         req.finish;
66
67 -%]
68       <item>
69         <title>[% mods.title() %]</title>
70         <link>http://gapines.org/opac/?target=record_result&page=0&mrid=[% mr_id %]&hits_per_page=10</link>
71         <description>
72                 &lt;b&gt;Author:&lt;/b&gt; [% mods.author() %]&lt;br&gt;
73                 &lt;b&gt;Subjects:&lt;/b&gt; 
74 [%-
75         FOREACH sub IN mods.subject();
76                 IF loop.count() > 5;
77                         ', ...';
78                         LAST;
79                 END;
80                 IF loop.index;
81                         ', ';
82                 END;
83                 sub.list.0;
84         END;
85 -%]
86         </description>
87       </item>
88 [%-
89
90 END;
91
92  -%]
93 </rss>