]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/opensearch.ttk
better support for ranking and OpenILL integration
[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://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                 '      <openIll:relevanceScale>' _ max_rank _ "</openIll:relevanceScale>\n";
76         END;
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.author();
93 -%]
94                 &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;
95 [%-
96         END;
97         IF mods.subject();
98 -%]
99                 &lt;b&gt;Subjects:&lt;/b&gt; 
100 [%-
101         FOREACH sub IN mods.subject();
102                 IF loop.count() > 3;
103                         ', ...';
104                         LAST;
105                 END;
106                 IF loop.index;
107                         ', ';
108                 END;
109                 -%]&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;[%-
110         END;
111 -%]&lt;br&gt;
112 [%-
113         END;
114 -%]
115                 &lt;b&gt;Copies Available:&lt;/b&gt; [% mr_id.2 %] 
116         </description>
117       </item>
118 [%-
119
120 END;
121
122  -%]
123   </channel>
124 </rss>