forked from yql/yql-tables
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.imageweb.xml
58 lines (51 loc) · 2.05 KB
/
search.imageweb.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Nagesh Susarla</author>
<documentationURL>See search.web and search.images for more details</documentationURL>
<sampleQuery>select * from {table} where query='pizza'</sampleQuery>
</meta>
<bindings>
<select itemPath="results.result" produces="XML">
<urls>
<url></url>
</urls>
<paging model="offset">
<start id="start" default="0" />
<pagesize id="count" max="50" />
<total default="10"/>
</paging>
<inputs>
<key id="query" type="xs:string" paramType="variable" required="true"/>
</inputs>
<execute><![CDATA[
var qs = query;
var webquery = 'select * from search.web(' + start + ',' + count + ') where query=@query';
var search = y.query(webquery, {query: qs}).results;
var images = [];
default xml namespace='http://www.inktomi.com/';
for each (var result in search.result) {
var theUrl = result.url;
// For any given URL from search only get the domain
// and use that as part of the search for images. This makes
// imagesearch much more richer
var idx = theUrl.indexOf("/", "http://".length);
if (idx > 0) {
theUrl = theUrl.substring(0, idx);
}
images.push(y.query('select * from search.images(1) where query=@query and url=@url', {url:theUrl, query:qs}));
}
var i = 0;
for each (var result in search.result) {
var image = images[i].results.result;
if (image) {
result.image = <image>{image}</image>;
}
i++;
}
response.object = search;
]]>
</execute>
</select>
</bindings>
</table>