-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit 13-Lab-Exercices.xqy
More file actions
82 lines (68 loc) · 1.9 KB
/
Unit 13-Lab-Exercices.xqy
File metadata and controls
82 lines (68 loc) · 1.9 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(:
let $location := cts:point(25.788969,-80.226439) (: downtown Miami, Florida :)
return
cts:search(
fn:doc(),
cts:element-pair-geospatial-query(
xs:QName("Place"),
xs:QName("Lat"),
xs:QName("Lon"),
cts:circle(200, $location)
)
)
(:
Modify this search to include a full text component as well as the geospatial component.
Find all documents that are:
Within a 200 mile radius of Miami, Florida
AND
Mention the word "shark", case insensitive, somewhere in the document.
:)
let $location := cts:point(25.788969,-80.226439) (: downtown Miami, Florida :)
let $results :=
cts:search(
fn:doc(),
cts:and-query((
cts:word-query(
"shark",
"case-insensitive"
),
cts:element-pair-geospatial-query(
xs:QName("Place"),
xs:QName("Lat"),
xs:QName("Lon"),
cts:circle(200, $location)
)
))
)
for $dive in $results/Dive
let $country := $dive//Country/text()
let $city := $dive//City/text()
let $site := $dive//Site/text()
let $depth := $dive//Depth/text()
let $lat := $dive//Lat/text()
let $lon := $dive//Lon/text()
let $marinelife := $dive//MarineLife
return
<match-summary>
<country>{$country}</country>
<city>{$city}</city>
<site>{$site}</site>
<depth>{$depth}</depth>
<latitude>{$lat}</latitude>
<longitude>{$lon}</longitude>
<marine-life>
{
for $animal in $marinelife//Animal/Type
return <animal>{$animal/text()}</animal>
}
</marine-life>
</match-summary>
:)
declare function local:get-coordinates($location){
let $request := fn:concat("http://maps.googleapis.com/maps/api/geocode/xml?address=", $location)
let $response := xdmp:http-get($request)
let $lat := $response[2]/GeocodeResponse/result[1]/geometry/location/lat
let $lng := $response[2]/GeocodeResponse/result[1]/geometry/location/lng
return
($lat, $lng)
};