简体   繁体   English

如何使用ArangoDB列出条目最相似的用户

[英]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: 例如:

  • user id: 112 has 3 tags (tags ids: 50, 51, 52, 53) 用户ID:112有3个标签(标签ID:50、51、52、53)
  • user id: 113 has 5 tags (tags ids: 52, 53, 54, 55, 56) 用户ID:113有5个标签(标签ID:52、53、54、55、56)
  • user id: 114 has 4 tags (tags ids: 51, 52, 53, 54) 用户ID:114具有4个标签(标签ID:51、52、53、54)
  • user id: 115 has 2 tags (tags ids: 48, 49) 用户ID:115有2个标签(标签ID:48、49)

When i searched user id 112 user. 当我搜索用户ID 112用户。 The results should be similar to this: 结果应与此类似:

  1. user id: 114 (3 matches, 51, 52, 53) 用户ID:114(3个匹配项,分别是51、52、53)
  2. user id: 113 (2 matches, 52, 53) 用户ID:113(2个匹配项,分别是52、53)

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中,只要您创建一个以userstags为顶点集合,以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.

相关问题 如何在 Neo4j 中找到具有最相似间接连接的节点 - How to find nodes with most similar indirect connections in Neo4j ArangoDB - 如何将neo4j 数据库导出导入ArangoDB - ArangoDB - how to import neo4j database export into ArangoDB 什么食谱与苹果烤饼最相似-按照与该食谱相似的顺序输出其他食谱的成分列表 - What recipe is the most similar to apple scones - output list of ingredients from other recipes in order of similarity to this recipe Cypher:我可以返回收藏集或类似收藏吗? - Cypher: can I return a collection of collections, or similar? 我应该使用Neo4j寻找类似用户还是坚持使用像MySQL这样的东西? - Should I use Neo4j for finding similar users or stick with something like MySQL? 如何通过互联网向用户公开交互式 neo4j 可视化(安全地)? - How can I expose an interactive neo4j visualization (safely) to users over the internet? ArangoDB文档数据库还有图形数据库?这怎么可能? - ArangoDB document database and also a graph database? How is it possible? 如何将列表(从“收集”)转换为字符串 - How Can I Convert a List (from Collect) Into a String 如何使用Cypher修改列表节点属性? - How Can I Revise a List Node Property Using Cypher? 列出密码中最连续的胜利 - List the most consecutive wins in cypher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM