在遍历中使用两个 ArangoSearch 视图
Using two ArangoSearch Views in a traversal
考虑以下数据集:
arangosh> db.createDocumentCollection('city')
arangosh> db.createDocumentCollection('colour')
arangosh> db._createEdgeCollection('likes')
LET cities =
[
{
"key": "1",
"cities": ["toronto", "kingston"]
},
{
"key": "2",
"cities": ["seattle", "kingston"]
},
{
"key": "3",
"cities": ["seat", "kingston"]
},
{
"key": "4",
"cities": ["toronto", "seattle"]
}
]
FOR c IN cities
INSERT c INTO city
RETURN NEW
LET colours = [
{
"key": "1",
"colors": ["red", "love green"]
},
{
"key": "2",
"colors": ["we like red", "blue and purple"]
},
{
"key": "3",
"colors": ["grassy green"]
},
{
"key": "4",
"colors": ["red"]
},
{
"key": "5",
"colors": ["red"]
},
{
"key": "6",
"colors": ["red", "green"]
}
]
FOR c IN colours
INSERT c INTO colour
RETURN NEW
LET likes = [
{
"from": "city/1", "to": "colour/3"
},
{
"from": "city/1", "to": "colour/1"
},
{
"from": "city/2", "to": "colour/3"
},
{
"from": "city/3", "to": "colour/2"
},
{
"from": "city/3", "to": "colour/3"
},
{
"from": "city/3", "to": "colour/5"
},
{
"from": "city/4", "to": "colour/5"
},
{
"from": "city/4", "to": "colour/6"
}
]
FOR l IN likes
INSERT l INTO likes
RETURN NEW
arangosh> db._createView("city_v", "arangosearch");
arangosh> var link = {
includeAllFields: false,
fields : { cities : { analyzers : [ "text_en" ] } }
};
arangosh> db._view("city_v").properties({ links: { city: link }});
arangosh> db._createView("colour_v", "arangosearch");
arangosh> var link = {
includeAllFields: false,
fields : { colors : { analyzers : [ "text_en" ] } }
};
arangosh> db._view("colour_v").properties({ links: { colour: link }});
FOR p IN city_v SEARCH ANALYZER (p.cities == 'toronto', 'text_en') RETURn p._id
returns
[
"city/1",
"city/4"
]
FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURn p._id
returns
[
"colour/1",
"colour/3",
"colour/6"
]
我需要帮助编写一个查询,该查询将 return city and colour
组合,其中 city
满足 toronto
的 ArangoSearchView,而 colours
满足green
.
的 ArangoSearchView
结果应该是:city/1 —> colour/3
and city/1 —> city/1
and city/4 —> city/6
虽然我知道这个例子可以使用 FULLTEXT 索引或其他一些 FILTER
机制,但目标是使用 ArangoSearch Views 的搜索功能来完成这个。
你会像这样稍微改变你的模型吗:
LET cities =
[
{
"_key": "1",
"cities": ["toronto", "kingston"]
},
{
"_key": "2",
"cities": ["seattle", "kingston"]
},
{
"_key": "3",
"cities": ["seat", "kingston"]
},
{
"_key": "4",
"cities": ["toronto", "seattle"]
}
]
FOR c IN cities
INSERT c INTO city
RETURN NEW
LET colours = [
{
"_key": "1",
"colors": ["red", "love green"]
},
{
"_key": "2",
"colors": ["we like red", "blue and purple"]
},
{
"_key": "3",
"colors": ["grassy green"]
},
{
"_key": "4",
"colors": ["red"]
},
{
"_key": "5",
"colors": ["red"]
},
{
"_key": "6",
"colors": ["red", "green"]
}
]
FOR c IN colours
INSERT c INTO colour
RETURN NEW
LET likes = [
{
"_from": "city/1", "_to": "colour/3"
},
{
"_from": "city/1", "_to": "colour/1"
},
{
"_from": "city/2", "_to": "colour/3"
},
{
"_from": "city/3", "_to": "colour/2"
},
{
"_from": "city/3", "_to": "colour/3"
},
{
"_from": "city/3", "_to": "colour/5"
},
{
"_from": "city/4", "_to": "colour/5"
},
{
"_from": "city/4", "_to": "colour/6"
}
]
FOR l IN likes
INSERT l INTO likes
RETURN NEW
和运行下面的查询:
LET clr = (FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURN p)
FOR doc IN city_v SEARCH ANALYZER (doc.cities == 'toronto', 'text_en')
FOR v,e,p in 1..1 OUTBOUND doc likes
filter p.vertices[1] in clr
RETURN {"v":v,"e":e,"p":p}
考虑以下数据集:
arangosh> db.createDocumentCollection('city')
arangosh> db.createDocumentCollection('colour')
arangosh> db._createEdgeCollection('likes')
LET cities =
[
{
"key": "1",
"cities": ["toronto", "kingston"]
},
{
"key": "2",
"cities": ["seattle", "kingston"]
},
{
"key": "3",
"cities": ["seat", "kingston"]
},
{
"key": "4",
"cities": ["toronto", "seattle"]
}
]
FOR c IN cities
INSERT c INTO city
RETURN NEW
LET colours = [
{
"key": "1",
"colors": ["red", "love green"]
},
{
"key": "2",
"colors": ["we like red", "blue and purple"]
},
{
"key": "3",
"colors": ["grassy green"]
},
{
"key": "4",
"colors": ["red"]
},
{
"key": "5",
"colors": ["red"]
},
{
"key": "6",
"colors": ["red", "green"]
}
]
FOR c IN colours
INSERT c INTO colour
RETURN NEW
LET likes = [
{
"from": "city/1", "to": "colour/3"
},
{
"from": "city/1", "to": "colour/1"
},
{
"from": "city/2", "to": "colour/3"
},
{
"from": "city/3", "to": "colour/2"
},
{
"from": "city/3", "to": "colour/3"
},
{
"from": "city/3", "to": "colour/5"
},
{
"from": "city/4", "to": "colour/5"
},
{
"from": "city/4", "to": "colour/6"
}
]
FOR l IN likes
INSERT l INTO likes
RETURN NEW
arangosh> db._createView("city_v", "arangosearch");
arangosh> var link = {
includeAllFields: false,
fields : { cities : { analyzers : [ "text_en" ] } }
};
arangosh> db._view("city_v").properties({ links: { city: link }});
arangosh> db._createView("colour_v", "arangosearch");
arangosh> var link = {
includeAllFields: false,
fields : { colors : { analyzers : [ "text_en" ] } }
};
arangosh> db._view("colour_v").properties({ links: { colour: link }});
FOR p IN city_v SEARCH ANALYZER (p.cities == 'toronto', 'text_en') RETURn p._id
returns
[
"city/1",
"city/4"
]
FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURn p._id
returns
[
"colour/1",
"colour/3",
"colour/6"
]
我需要帮助编写一个查询,该查询将 return city and colour
组合,其中 city
满足 toronto
的 ArangoSearchView,而 colours
满足green
.
结果应该是:city/1 —> colour/3
and city/1 —> city/1
and city/4 —> city/6
虽然我知道这个例子可以使用 FULLTEXT 索引或其他一些 FILTER
机制,但目标是使用 ArangoSearch Views 的搜索功能来完成这个。
你会像这样稍微改变你的模型吗:
LET cities =
[
{
"_key": "1",
"cities": ["toronto", "kingston"]
},
{
"_key": "2",
"cities": ["seattle", "kingston"]
},
{
"_key": "3",
"cities": ["seat", "kingston"]
},
{
"_key": "4",
"cities": ["toronto", "seattle"]
}
]
FOR c IN cities
INSERT c INTO city
RETURN NEW
LET colours = [
{
"_key": "1",
"colors": ["red", "love green"]
},
{
"_key": "2",
"colors": ["we like red", "blue and purple"]
},
{
"_key": "3",
"colors": ["grassy green"]
},
{
"_key": "4",
"colors": ["red"]
},
{
"_key": "5",
"colors": ["red"]
},
{
"_key": "6",
"colors": ["red", "green"]
}
]
FOR c IN colours
INSERT c INTO colour
RETURN NEW
LET likes = [
{
"_from": "city/1", "_to": "colour/3"
},
{
"_from": "city/1", "_to": "colour/1"
},
{
"_from": "city/2", "_to": "colour/3"
},
{
"_from": "city/3", "_to": "colour/2"
},
{
"_from": "city/3", "_to": "colour/3"
},
{
"_from": "city/3", "_to": "colour/5"
},
{
"_from": "city/4", "_to": "colour/5"
},
{
"_from": "city/4", "_to": "colour/6"
}
]
FOR l IN likes
INSERT l INTO likes
RETURN NEW
和运行下面的查询:
LET clr = (FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURN p)
FOR doc IN city_v SEARCH ANALYZER (doc.cities == 'toronto', 'text_en')
FOR v,e,p in 1..1 OUTBOUND doc likes
filter p.vertices[1] in clr
RETURN {"v":v,"e":e,"p":p}