[英]Using two ArangoSearch Views in a traversal
Consider the following dataset: 考虑以下数据集:
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 FOR p IN city_v SEARCH ANALYZER (p.cities == 'toronto', 'text_en') RETURn p._id
返回
[
"city/1",
"city/4"
]
FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURn p._id
returns FOR p IN colour_v SEARCH ANALYZER (p.colors == 'green', 'text_en') RETURn p._id
返回
[
"colour/1",
"colour/3",
"colour/6"
]
I need help with writing a query that would return the city and colour
combinations where city
satisfies the ArangoSearchView of toronto
that like colours
that satisfy the ArangoSearchView of green
. 我需要编写查询来返回
city and colour
组合,其中city
满足toronto
的ArangoSearchView,就像满足green
ArangoSearchView的colours
一样,我需要帮助。
The result sould be: city/1 —> colour/3
and city/1 —> city/1
and city/4 —> city/6
结果为:
city/1 —> colour/3
和city/1 —> city/1
和city/4 —> city/6
While I understand that this example could use a FULLTEXT index or some other FILTER
mechanism, the goal is to use the search features of ArangoSearch Views to accomplish this. 虽然我知道此示例可以使用FULLTEXT索引或其他
FILTER
机制,但目标是使用ArangoSearch视图的搜索功能来完成此操作。
Would you slightly change your model like this: 您是否可以像下面那样稍微更改模型:
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
And run the query below: 并运行以下查询:
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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.