[英]How can I list the users with the most similar entries with ArangoDB
I started new project today. 我今天开始新项目。 I have users table, tags table and user_tags edge for graph results.
我有用户表,标签表和user_tags边缘的图形结果。
I attached to users some tags on graph. 我在图形上附加了一些标签给用户。 How can I list the users with the most similar entries with ArangoDB.
如何列出与ArangoDB条目最相似的用户。
For example: 例如:
When i searched user id 112 user. 当我搜索用户ID 112用户。 The results should be similar to this:
结果应与此类似:
Non-common data should not come within results user id: 115 非常见数据不应包含在结果用户ID中:115
If no one knows arangodb solution, I can use neo4j if there is a solution with neo4j. 如果没有人知道arangodb解决方案,如果有neo4j解决方案,我可以使用neo4j。
Thanks. 谢谢。
In cypher, this is the query : 在cypher中,这是查询:
MATCH (u1:User {id:114})-[:HAS_TAG]->(tag:Tag),
(u:User)-[:HAS_TAG]->(tag:Tag)
WITH u, collect(id(tag)) AS tags
RETURN u, tags, size(tags) AS score
ORDER BY score DESC
Cheers 干杯
In ArangoDB, this query will work, so long as you create a graph with users
and tags
as vertex collections, and user_tags
as your edge collection: 在ArangoDB中,只要您创建一个以
users
和tags
为顶点集合,以user_tags
作为边集合的图形,此查询就可以使用:
LET active_user = FIRST(
FOR u IN users
FILTER u.id == @user_id
RETURN u._id
)
LET active_tags = (
FOR v IN 1..10 OUTBOUND active_user GRAPH 'user_tags_graph'
RETURN (v.id)
)
FOR u IN users
FILTER u._id != active_user
LET tags_in_use = FLATTEN(
FOR v IN 1..10 OUTBOUND u._id GRAPH 'user_tags_graph'
RETURN [v.id]
)
LET tag_matches = (
RETURN LENGTH(INTERSECTION(active_tags, tags_in_use))
)
FILTER FIRST(tag_matches) > 0
SORT tag_matches DESC
RETURN {
[u.id]: INTERSECTION(active_tags, tags_in_use)
}
It can probably be optimised heavily but breaking it out like this made it easier to understand. 可能可以对其进行大量优化,但是像这样将其分解会使它更易于理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.