Arangodb - Hands-On Labs - Section b - Arangodb Development (2)
Arangodb - Hands-On Labs - Section b - Arangodb Development (2)
TRAINING
Hands On Labs
Version 0.7
1.1 CREDENTIALS.................................................................................................... 3
1.2 LICENSE KEY.................................................................................................... 3
1.3 LIST OF ENVIRONMENTS...................................................................................... 4
2 ARANGODB DEVELOPMENT.................................................................................... 5
Page 1 of 59
2.1.30 LAB B-30: OPTIMIZE PERSON QUERIES.........................................................................34
2.1.31 LAB B-31: GEOSPATIAL QUERIES...................................................................................35
2.1.32 LAB B-32: LET AND JOINS...........................................................................................37
2.1.33 LAB B-33: JOIN MULTIPLE COLLECTIONS.....................................................................38
2.1.34 LAB B-34: SUBQUERIES...............................................................................................39
2.1.35 LAB B-35: AIRPORTS BY STATE...................................................................................40
2.1.36 LAB B-36: COUNT BY YEAR BORN................................................................................41
2.1.37 LAB B-37: AGGREGATE BY DECADE..............................................................................41
2.1.38 LAB B-38: FULL DOC COLLECTION..............................................................................42
2.1.39 LAB B-39: DISTINCT RELATIONS..................................................................................43
2.1.40 LAB B-40: ITERATE AND COUNT NON-COLLECTION DATA.............................................43
2.1.41 LAB B-41: L.O.T.R TRAVERSAL....................................................................................44
2.1.42 LAB B-42: CO-ACTORS OF VIGGO MORTENSON............................................................45
2.1.43 LAB B-43: K_SHORTEST_PATH...............................................................................46
2.1.44 LAB B-44: CREATE A SEARCH VIEW............................................................................46
2.1.45 LAB B-45 BASIC SEARCH............................................................................................50
2.1.46 LAB B-46 PHRASE SEARCH..........................................................................................52
2.1.47 LAB B-47 WORD PROXIMITY PHRASE SEARCH...............................................................54
2.1.48 LAB B-48 SCORING ALGORITHMS.................................................................................55
Page 2 of 59
ARANGODB TRAINING: HANDS-ON LABS
1.1 CREDENTIALS
Use the following credentials to log in to the lab environments.
# Environment Username Password Ports
1. ssh arangolabs $umm3r$un 22
2. Web UI root $umm3r$un 8529,
18529,
28529
38529,
45829
3. jupyter-labs @utumnL3@v3$ 8080
1.2LICENSE KEY
NOTE: Instructor to paste the latest license key here. The validUntil needs to be at
least until the last day of the training
{
"license": "license":
"eyJncmFudCI6ImV5Sm1aV0YwZFhKbGN5STZleUpsZUhCcGNtVnpJam
94TnpRNE56WXhNVGs1ZlN3aWJtOTBRbVZtYjNKbElqb2lNakF5TlMwd
05DMHlPRlF4TXpvMU56b3dNVm9pTENKdWIzUkJablJsY2lJNklqSXdN
alV0TURZdE1ERlVNRFk2TlRrNk5UbGFJaXdpYzNWaWFtVmpkQ0k2ZXl
KbGJXRnBiQ0k2SW5KaGFuVkFZbXgxWlhCaGJDNWpiMjBpZlN3aWFYTn
pkV1Z5SWpwN0ltTnZiWEJoYm5raU9pSkJjbUZ1WjI5RVFpQkhiV0pJS
Wl3aWJtRnRaU0k2SWxScGJHeHRZVzRnUkdsemMyVnNhMkZ0Y0NJc0lt
VnRZV2xzSWpvaWRHbHNiV0Z1TG1ScGMzTmxiR3RoYlhCQVlYSmhibWR
2WkdJdVkyOXRJbjBzSW1OMWMzUnZiV1Z5SWpwN0ltNWhiV1VpT2lKQ2
JIVmxjR0ZzSWl3aVpXNTJhWEp2Ym0xbGJuUWlPaUpRWVhKMGJtVnlJR
lJ5WVdsdWFXNW5JaXdpYjJWdElqb2lJbjBzSW5abGNuTnBiMjRpT2pG
OSIsInNpZ25hdHVyZSI6IkFuUm1jbnFyUGJYbHk2bmJIVkdyZVFHcGQ
3TTNaWHJhVnFoNHY3cS9ta2tNOVBwcFA0eGVlNTNyVXdMNk94bWFIZW
RNYTZGYkxpa3pyS3hFNWcvUTRHWHc2OTdqeUdhVVlpMGVkTnhXMDJ0Q
Page 3 of 59
ARANGODB TRAINING: HANDS-ON LABS
UVXS2RUZy9vV0lKQ2VnTUxTeTk0Vm4yT3VkWENiYVNUQkw5V3NRZjlK
MVJpRm5CZFhRTHZCc0cwd3ZQRzF2Y1VhZ1RwUUNqU20vUWExZXliZzB
0bDdaOUZEZXE3bWpiVmFncHVTZk1EV0orenF3VFFpWmJRbnc2eUxwbV
BLM1lkam94eXVLUDNVWWViM1kxRnQzTm9Fc01DdThxRGNHWVVSV1NyO
GwzclI2YWlBN2Z5dmhIZG8xYTFnUzRJYytqcERXdGc5bTl3K2swR2NW
c3JXRU5TaW10dFVMNUNIZmRGNFM4OEptU1Bpdz09In0=",
"validUntil": "2025-31-05T23:59:59Z",
"validUntilLocal": "5/31/2025",
"daysToExpiry": 24
}
Page 4 of 59
ARANGODB TRAINING: HANDS-ON LABS
2 ARANGODB DEVELOPMENT
2.1INSTALLATION / ENVIRONMENT READINESS
1. Login to your instance you selected in Section 1.3 using the credentials
provided
curl -L http://localhost:8529
6. Next try accessing the arangodb instance remotely by entering the following
url into your browser
http://<your hostname>:8529
7. The host access should fail
1. Make sure you are logged to your instance you selected in Section 1.3 using
the credentials provided
2. Enable remote access for your deployment by editing the arangod.conf
Page 5 of 59
ARANGODB TRAINING: HANDS-ON LABS
sudo vi /etc/arangodb3/arangod.conf
3. Edit the following line:
4. Original Line:
endpoint = tcp://127.0.0.1:8529
5. Edited Line:
endpoint = tcp://0.0.0.0:8529
6. Make sure you are editing the line which is not commented i.e. does not
start with #
7. Save your edits and quit
8. Start your arangodb instance
http://<your hostname>:8529
11. Your access to the environment should now succeed
1. Make sure you are logged to your instance you selected in Section 1.3 using
the credentials provided
2. Stop your arangodb instance
sudo arango-secure-installation
4. Specify and confirm your ‘root’ password once requested
5. Navigate to:
Page 6 of 59
ARANGODB TRAINING: HANDS-ON LABS
http://<your hostname>:8529
6. Login with the password you just specified for root
1. Make sure you are logged to your instance you selected in Section 1.3 using
the credentials provided
arangosh
3. Enter your root password when prompted
4. Run the following command the prompt:
http://<your hostname>:8529
Page 7 of 59
ARANGODB TRAINING: HANDS-ON LABS
2. Validate your ArangoDB version on the bottom-left and top-left. The actual
version number may vary depending upon when this lab was conducted.
3. Verify the username being used and the database you are connected to.
4. Navigate to the Dashboard > Statistics look at the summary metrics being
presented
5. Navigate to the Dashboard > System Resources look at the summary
metrics being presented
Page 8 of 59
ARANGODB TRAINING: HANDS-ON LABS
6. Navigate to the Dashboard > Metrics and look at the counters being
presented.
7. These counters are also exposed via the Prometheus exporter for use in
tools such as Grafana, DataDog, etc.
8. Scroll down further to review the histograms
9. Explore other sections of the interface (you will need them later)
4. The Starter uses the next few ports above the Starter port for the cluster
nodes. If you use port 8528 for the Starter
5. The Coordinator uses 8529 (=8528+1)
6. The DB-Server 8530 (=8528+2)
Page 9 of 59
ARANGODB TRAINING: HANDS-ON LABS
ps -ef|grep arangodb
16. You should be able to see the following:
a. 3 Starter processes
b. 3 DB Server Subprocesses
c. 3 Coordinator Subprocesses
d. 3 Agency subprocesses
17. Check the ptree of the primary agency process using
Page 10 of 59
ARANGODB TRAINING: HANDS-ON LABS
pstree <pid> -a
18. Note: To simulate the scenario, all processes and starters were started on
the same machine; this is great for development. In production, however,
you will end up deploying these processes on different machines.
19. At times, the agency, coordinator, and observers could all be on different
machines. You can make this differentiation by specifying --cluster.role
either as PRIMARY or DBSERVER or --cluster.role as COORDINATOR
20. Agency is activated using --agency.activate true
5. Click the _SYSTEM link on the top right to switch to the newly created
database
Page 11 of 59
ARANGODB TRAINING: HANDS-ON LABS
6. Choose test from the screen and click the green Select DB:test button
7. Create a collection
8. Click COLLECTIONS on the left navigation
9. Click (+) Add Collection
10. Specify the collection name as mycollection
11. Leave the rest as defaults and click Save
Page 12 of 59
ARANGODB TRAINING: HANDS-ON LABS
14. Copy the _id field from the result and use it to access the document and get
only the last name
RETURN DOCUMENT("mycollection/33780").lname
15. BONUS:
16. Navigate to COLLECTIONS
17. Click mycollection
18. Click Content
19. Review the documents created
20. Manually create a document using the (+) green sign on the top right corner
1. You can either use the local arangosh installed on your training server or
choose to install the client tools locally on your machine. The client tools can
be found here:
Page 13 of 59
ARANGODB TRAINING: HANDS-ON LABS
https://arangodb.com/download/
2. Once you have installed the client you can use arangosh to connect to a
deployment
3. Simply typing arangosh will try and connect to a local deployment on 8529
4. To connect to a specific deployment use:
arangosh --help
7. Let's go through a few basic usage steps
8. To create a database
localhost:18529@_system> db._createDatabase("mydb");
9. To use the created database
localhost:18529@_system> db._useDatabase("mydb");
10. To get additional help:
localhost:18529@_system> db._help();
11. To run a for loop:
Page 14 of 59
ARANGODB TRAINING: HANDS-ON LABS
3. Switch into the newly created database by clicking _SYSTEM at the top right
corner
Page 15 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 16 of 59
ARANGODB TRAINING: HANDS-ON LABS
5. Next create a collection with a replication factor of 4 does it work? Why not?
localhost:28529@_system> db._useDatabase("testdb")
7. Repeat the process via arangosh
localhost:28529@testdb> db._create("mycollection",
{ replicationFactor: 4 }, { enforceReplicationFactor: false
});
8. Does it work? Why? What's happening in the back end?
9. Next edit the collection properties and set the writeConcern to 4. Will it
work? Why or Why not?
Page 17 of 59
ARANGODB TRAINING: HANDS-ON LABS
RETURN DECODE_REV("_h_59XG6--A")
12. What does the output show? What timezone is the output?
NOTE: Revision Ids are meant for optimistic locking and debugging only please
do not build business logic on the decoded value, the implementation may
change in the future
Page 18 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Run the following AQL query, by replacing your last obtained revision id in
<YOUR REVISION ID>
Page 19 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Query by _id:
return DOCUMENT('airports/SFO')
2. Query by _key:
return DOCUMENT('airports','SFO')
Page 20 of 59
ARANGODB TRAINING: HANDS-ON LABS
return DOCUMENT(['airports/SFO','airports/JFK'])
14. Read multiple documents by _key:
return DOCUMENT('airports',['SFO','OAK','JFK'])
15. Read multiple documents from different collections:
RETURN DATE_NOW()
4. Run the following query
RETURN DATE_ISO8601(DATE_NOW())
Page 21 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 22 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Default behavior of the return is to simply return the results in the order the
were returned or consolidated
4. You can sort by multiple keys; lets sort by state first (ascending) and then
city (descending)
Page 23 of 59
ARANGODB TRAINING: HANDS-ON LABS
b. JSON format:
Page 24 of 59
ARANGODB TRAINING: HANDS-ON LABS
7. You can also run the AQL query below, the created document will not be
returned:
9. The following query is analogous to the previous query, quotes are not
required on the field names however are required on string values
Page 25 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Let's create a document first which we can use to learn about all the
supported UPDATE operations update, replace, repset, upsert:
[
{
"_key": "test-update",
"_id": "scratch/test-update",
"_rev": "_gdrxqkm--_",
"field1": "foo-updated",
"field2": "bar",
"field3": "baz",
"field4": "new-field"
}
]
Page 26 of 59
ARANGODB TRAINING: HANDS-ON LABS
5. The following AQL is a short form version of the update with different fields,
but yields identical results
[
{
"_key": "test-update",
"_id": "scratch/test-update",
"_rev": "_gdr1Bzq--A",
"field1": "foo-updated",
"field2": "bar-updated",
"field3": "baz",
"filed4": "new-field",
"field5": "new-field"
}
]
7. Note:
2. You should see the following result, null as the old document and the full
new document, indicating the document was inserted
Page 27 of 59
ARANGODB TRAINING: HANDS-ON LABS
[
[
null,
{
"_key": "test-upsert",
"_id": "scratch/test-upsert",
"_rev": "_gdslqDa---",
"field1": "foo",
"field2": "bar",
"field3": "baz"
}
]
]
3. Running the same AQL query multiple times you should see the following
results:
o Run #2: Original document, plus field1 is updated and field2 is added
[
[
{
"_key": "test-upsert",
"_id": "scratch/test-upsert",
"_rev": "_gdslqDa---",
"field1": "foo",
"field2": "bar",
"field3": "baz"
},
{
"_key": "test-upsert",
"_id": "scratch/test-upsert",
"_rev": "_gdslt_C---",
"field1": "foo-updated",
"field2": "bar",
"field3": "baz",
"field4": "new-field"
}
Page 28 of 59
ARANGODB TRAINING: HANDS-ON LABS
]
]
[
[
{
"_key": "test-upsert",
"_id": "scratch/test-upsert",
"_rev": "_gdslt_C---",
"field1": "foo-updated",
"field2": "bar",
"field3": "baz",
"field4": "new-field"
},
{
"_key": "test-upsert",
"_id": "scratch/test-upsert",
"_rev": "_gdsl3Pe--_",
"field1": "foo-updated",
"field2": "bar",
"field3": "baz",
"field4": "new-field"
}
]
]
DANGER
Upsert operations can be run without specifying a _key in the
upsertExpression, but the behavior is undefined if more than one
document matches the upsert operation
Per the official documentation here:
Page 29 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Lets create a document first which we can use to learn about all the
supported UPDATE operations update, replace, repset, upsert:
[
{
"_key": "test-replace",
"_id": "scratch/test-replace",
"_rev": "_gdr8uVW--A",
"field6": "foo-updated",
"field7": "new-field"
}
]
NOTE:
Page 30 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 31 of 59
ARANGODB TRAINING: HANDS-ON LABS
for p in Person
return MERGE(KEEP(p,'name'),{'born': p.born <= 1000 ? "**Bad
Data**": p.born})
Page 32 of 59
ARANGODB TRAINING: HANDS-ON LABS
11. What happens when you remove one of the @ from the binding?
12. Note: @@ is used for collections while @ is using for other singular
parameters
13. Here is an example of changing the @@ to @ and using an array instead
[
{"name": "dateISO8601",
"expression": "RETURN DATE_ISO8601(DATE_NOW())",
"overwrite": true,
"computeOn": ["insert","update", "replace"]
},
{"name": "dateEpoch",
Page 33 of 59
ARANGODB TRAINING: HANDS-ON LABS
for id in 1..10
insert {_key:CONCAT(id,"::doc")} into scratch
return NEW
5. You should see an output similar to this:
6. BONUS:
a. Try updating one or more documents. What do you see?
Page 34 of 59
ARANGODB TRAINING: HANDS-ON LABS
b. Change the computeOn settings and try the same. What difference
do you see?
FOR p IN Person
FILTER p.name == "Viggo Mortensen"
RETURN p
3. Find all the Jon* in the database
FOR p IN Person
FILTER p.name like 'Jon%'
RETURN p
4. Run the same query but sort it by year born
5. Run an explanation for each of those queries. What do you see?
6. Run a profile for each of those queries. What do you see?
FOR p IN Person
RETURN {name: p.name, born: p.born}
2. What do you need to do here? (Hint: you need to use LIMIT)
3. Extend what you just did to order the list by born followed by name
4. Run a profile for each of those queries. What do you see? What is the query
doing, and where??
Page 35 of 59
ARANGODB TRAINING: HANDS-ON LABS
7. Profile the 3 queries again in the previous labs what do you see?
8. Create a composite index on name and born (name, born) and run a profile
what do you see?
9. Create an index on born ONLY and run a profile what do you see?
Page 36 of 59
ARANGODB TRAINING: HANDS-ON LABS
11. The results in addition to JSON and Table formats, the data can be
displayed in Geospatial format on a map
12. Next let's find the airports to this location (< 10,000 meters)
a. Hertz Rental: 25 Bowery Bay Blvd, Queens, NY 11371
b. The Lat, Long: 40.76949,-73.88626
13. Find the GEO_DISTANCE between this location and all the other airports in
NY
a. Filter to all airport locations < 10,000 meters
b. Display the points on the map
14. Look at the profile of the query, is the query efficient
15. Create appropriate indexes to make the query more efficient
16. How are your queries more efficient with the indexes? What changed?
17. Solution:
a. Create a persistent index on state
b. Create a geospatial index on lat and long
c. Use GEO_DISTANCE (lat1,long1,lat2,long2) to calculate the distance
d. Filter to all airports < 10,000
e. Note: GEO_POINT is long,lat and NOT lat,long
Page 37 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Variables using let may be defined for various reasons, including code
readability
2. Sometimes it becomes complex or even impossible to put the whole query
in a single nested combination of for loops, filters, and sorts.
3. Often, it’s easier to extract some data separately. That’s where LET comes
in handy.
4. Say we want to find out options to get to SFO in 2 stops starting from Tampa
International (TPA) to San Francisco International (SFO), we could first find
out which airports can be reached directly from TPA, then for each of these
do a separate query to see which of those go to SFO.
5. Here is one way to get to the end goal:
let hops = (
for f IN flights
filter f._from == 'airports/TPA'
6. Now that we have all flights going out from Tampa International(TPA), we
can determine which flights go to San Francisco International (SFO)
for h IN hops
for f IN flights
filter f._to == 'airports/SFO'
filter f._from == h._to
Page 38 of 59
ARANGODB TRAINING: HANDS-ON LABS
let journey = {
"Path": CONCAT_SEPARATOR(" -> ",h._from,f._from,f._to),
"Distance Total": (h.Distance + f.Distance),
"Distance Leg1": h.Distance,
"Distance Leg2": f.Distance
}
sort journey.`Distance Total` desc, journey.`Distance Leg2`
desc, journey.`Distance Leg1` desc
1. Retrieve all actors along with the movies they acted in:
a. Persons are actors if they are linked to movies via documents in the
"Relation" collection with a "type" attribute value of "acted_in"
b. Persons and movies are referenced from the "Relation" collection via
the "_from" and "_to" attributes.
c. You will thus need to join the collections "Person", "Movie" and
"Relation"
d. Example:
{
"_id" : "Relation/8309",
"_from" : "Person/86", /* refers to Person collection */
"_to" : "Movie/82", /* refers to Movie collection */
"role" : "Wolf",
"type" : "acted_in" /* Want Relations of this type */
}
{
"_id" : "Person/86", /* refers to a Person */
"name" : "Harvey Keitel"
}
{
"_id" : "Movie/82", /* refers to a Movie */
"title" : "Pulp Fiction"
}
Page 39 of 59
ARANGODB TRAINING: HANDS-ON LABS
{
"_id" : "Relation/10406",
"_from" : "Movie/641", /*refers to Movie collection*/
"_to" : "Genre/17", /*refers to Genre collection*/
"type" : "has_genre"
Page 40 of 59
ARANGODB TRAINING: HANDS-ON LABS
{
"_id" : "Movie/641", /* this is the referred-to Movie*/
"title" : "The Lord of the Rings: The Return of the King"
}
{
"_id" : "Genre/17", /*this is the referred-to Genre*/
"name" : "Adventure"
}
Page 41 of 59
ARANGODB TRAINING: HANDS-ON LABS
3. BONUS:
a. Order from the results from the most to the least airports
Page 42 of 59
ARANGODB TRAINING: HANDS-ON LABS
2. How would you aggregate by decade, Hint: You need to use min and max
3. Solution:
Page 43 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 44 of 59
ARANGODB TRAINING: HANDS-ON LABS
1. Group all movies in the "Movie" collection by the following duration ranges:
Page 45 of 59
ARANGODB TRAINING: HANDS-ON LABS
5. SOLUTION:
RETURN {
duration: CONCAT(duration[0], ' - ', duration[1]),
count: group.count,
min: group.min,
max: group.max
}
1. Retrieve all "Lord of the Rings" movies with their direct relations.
a. Start by iterating over the "Movies" collection to find the relevant
movies, and for each of them, start a traversal with the direction
"ANY" on the "Relation" collection.
b. For each relation, return the type of the relation plus the related
document
5. Switch to the movies database
Page 46 of 59
ARANGODB TRAINING: HANDS-ON LABS
title: movie.title,
relation: {
type: e.type,
value: v
}
}
6. The above query will return an error , why?
7. Add the following to the query at the very beginning:
1. Write an AQL query that finds all the co-actors of Viggo Mortensen
a. First, try to find all the movies that Viggo Mortensen acted in
b. Then, find other persons who acted in the same movies.
2. Step 1: Get the Actor Id
/* Step 1 */
LET viggo = (
FOR actor IN Person
FILTER actor.name =~ "^Viggo"
RETURN actor._id
)[0]
RETURN viggo
3. Step 2: Get the movies with Viggo
LET viggo = (
FOR actor IN Person
FILTER actor.name =~ "^Viggo"
RETURN actor._id
)[0]
LET moviesWithViggo = (
FOR v,e,p IN OUTBOUND viggo Relation
FILTER p.edges[0].type == 'acted_in'
RETURN v._id
Page 47 of 59
ARANGODB TRAINING: HANDS-ON LABS
RETURN moviesWithViggo
2. Step 3: Get all the Relations for acted_in
LET viggo = (
FOR actor IN Person
FILTER actor.name =~ "^Viggo"
RETURN actor._id
)[0]
LET moviesWithViggo = (
FOR v,e,p IN OUTBOUND viggo Relation
FILTER p.edges[0].type == 'acted_in'
RETURN v._id
)
FOR movie IN moviesWithViggo
FOR v,e,p IN INBOUND movie Relation
FILTER p.edges[0].type == 'acted_in'
FILTER v._id != viggo
RETURN DISTINCT v.name
with airports
for path IN outbound all_shortest_paths 'airports/TPA' to
'airports/SFO' flights
options {
weightAttribute: "Distance"
}
return path
Page 48 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 49 of 59
ARANGODB TRAINING: HANDS-ON LABS
"links": {
"points-of-interest": {
"analyzers": [
"identity"
],
"fields": {
"description": {
Page 50 of 59
ARANGODB TRAINING: HANDS-ON LABS
"analyzers": [
"text_en",
"identity"
]
},
"title": {
"analyzers": [
"text_en",
"identity"
]
}
},
"includeAllFields": true,
"storeValues": "none",
"trackListPositions": false
}
}
Page 51 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 52 of 59
ARANGODB TRAINING: HANDS-ON LABS
[
{
"_key": "20130659",
"_id": "points-of-interest/20130659",
"_rev": "_giji-7S---",
"alt": "{{IATA|SFO}}",
"article": "San Francisco",
"description": "Located about 10 mi
(16 km) south of the city, is the Bay Area's major
international airport (and one of the busiest in the
nation) and has numerous passenger amenities including a
wide range of food and drink establishments, shopping,
baggage storage, public showers, a medical clinic, and
assistance for lost or stranded travelers and military
personnel. SFO has four terminals; as a rule of thumb,
Alaska Airlines and American Airlines use Terminal 2,
United Airlines has Terminal 3, most other domestic
carriers use Terminal 1, and all foreign airlines use the
International Terminal. SFO is infamous for its weather
delays, so check if Oakland Airport has service from your
origin as well. Oakland is closer to Downtown San
Francisco than SFO is and fog free.",
"lastEdit": "2019-09-02",
"latitude": 37.618889,
"longitude": -122.375,
"phone": "+1-800-435-9736",
"title": "San Francisco International Airport",
"type": "go",
"url": "https://FlySFO.com",
"wikidata": "Q8688"
}
Page 53 of 59
ARANGODB TRAINING: HANDS-ON LABS
[
{
"_key": "20131814",
"_id": "points-of-interest/20131814",
"_rev": "_gijiAAK--h",
"article": "James Bond tourism",
"description": "Featured in ''A View to a Kill''
(1985).",
"directions": "United States",
"latitude": 37.75769,
"longitude": -122.47261,
"title": "San Francisco",
"type": "other"
},
{
"_key": "20133355",
"_id": "points-of-interest/20133355",
"_rev": "_gijhmA2--A",
"article": "Marvel Cinematic Universe",
"description": "The majority of the film takes
place here.",
"directions": "California, United States",
"latitude": 37.801944,
"longitude": -122.418889,
"title": "San Francisco",
"type": "other",
"wikidata": "Q62"
},
{
"_key": "20133872",
"_id": "points-of-interest/20133872",
"_rev": "_gijhmIu--C",
"article": "Chocolate",
"description": "A city with a thriving chocolate
Page 54 of 59
ARANGODB TRAINING: HANDS-ON LABS
6. The default search is exact search, for the full string with == and is case
sensitive
7. Is recommended to specify the analyzer being used, so that the context is
clear to the developer
1. If you need to search for a phrase in the document, you will instead use the
following:
[
{
"_key": "20130050",
"_id": "points-of-interest/20130050",
"_rev": "_giji-Cm-AD",
"address": "114 East Spain Street, Sonoma",
"alt": "Sonoma State Historic Park",
"article": "El Camino Real",
"description": "Founded in 1823 as the last of the
Spanish missions, in part by Mariano Vallejo to check the
Page 55 of 59
ARANGODB TRAINING: HANDS-ON LABS
Page 56 of 59
ARANGODB TRAINING: HANDS-ON LABS
"wikidata": "Q8688"
},
{
"_key": "20130865",
"_id": "points-of-interest/20130865",
"_rev": "_giji_HG--1",
"address": "1 Old Bayshore Highway",
"article": "San Francisco International Airport",
"image": "Millbrae, CA, USA - panoramio.jpg",
"lastEdit": "2019-10-05",
"latitude": 37.603429,
"longitude": -122.376155,
"phone": "+1 650 692-3500",
"title": "The Westin San Francisco Airport",
"type": "sleep",
"url":
"https://www.marriott.com/hotels/travel/sfowi-the-westin-
san-francisco-airport/"
},
{
"_key": "20130866",
"_id": "points-of-interest/20130866",
"_rev": "_giji_HG-_D",
"address": "401 E Millbrae Ave",
"article": "San Francisco International Airport",
"image": "Aloft San Francisco Airport.jpg",
"lastEdit": "2019-10-05",
"latitude": 37.603164,
"longitude": -122.377678,
"phone": "+1 650 443-5500",
"title": "Aloft San Francisco Airport",
"type": "sleep",
"url":
"https://www.marriott.com/hotels/travel/sfoal-aloft-san-
francisco-airport/"
},
...
Page 57 of 59
ARANGODB TRAINING: HANDS-ON LABS
for p in wikiVoyage
search Phrase(p.title,"Aloft",2,"Airport",'text_en')
limit 10
return p
3. Those are too few results, what do you need to do to get more results?
4. Hint: Try and use additional OR conditions to find more results, try adding
Hilton to your query
5. SOLUTION:
for p in wikiVoyage
search Phrase(p.title,"Aloft",2,"Airport",'text_en') or
Phrase(p.title,"Aloft",1,"Airport",'text_en') or
Phrase(p.title,"Hilton",1,"Airport",'text_en') or
Phrase(p.title,"Hilton",2,"Airport",'text_en')
return p
FOR p IN wikiVoyage
SEARCH ANALYZER ( p.description IN keywords, 'text_en')
SORT BM25 (p) DESC
LIMIT 10
RETURN p
2. Change the algorithm to TFIDF do you see any difference in the ranking?
Page 58 of 59