ArangoDB图数据库应用探索

Posted 78 months ago arangodb 图数据库 搜索 智能推荐

title: ArangoDB 图数据库 应用探索

ArangoDB 图数据库 应用探索

Not Only SQL

ArangoDB {:&.flexbox.vleft}

ArangoDB 图数据库场景

行为分析 社会关系 风险控制 人脉管理

现实应用 {:&.flexbox.vleft}

App应用商店关系分析 {:&.flexbox.vleft}

App应用商店关系分析 {:&.flexbox.vleft}

用户集合

生成五千个随机用户数据


for user in 1..5000
    INSERT {
            "date":(DATE_NOW()+FLOOR(RAND()*100)),
            "info":CONCAT("附加信息",user)
            } IN users return NEW

  {
    "_key": "40502",
    "_id": "users/40502",
    "_rev": "_WfKeWT---C",
    "date": 1520739311982,
    "info": "附加信息3362"
  }

App应用商店关系分析 {:&.flexbox.vleft}

app集合

生成一万个随机APP数据

for app IN 1..10000
    INSERT {"name":CONCAT("app",app)}
    INTO apps

  {
    "_key": "64203",
    "_id": "apps/64203",
    "_rev": "_WfKkWO2-_v",
    "name": "app9922"
  }

App应用商店关系分析 {:&.flexbox.vleft}

分类集合

生成六个随机分类

for doc IN 1..6
    INSERT {
        "name":CONCAT("classify",doc)
            } INTO classify
    RETURN NEW


{
"_key": "64881",
"_id": "classify/64881",
"_rev": "_WfKpDZW--_",
"name": "classify2"
}

App应用商店关系分析 {:&.flexbox.vleft}

公司集合

生成三百个随机公司

for doc IN 1..300
    INSERT {
        "name":CONCAT("company",doc)
            } INTO company
    RETURN NEW

{
    "_key": "65022",
    "_id": "company/65022",
    "_rev": "_WfKq8fW---",
    "name": "company1"
}

App应用商店关系生成 {:&.flexbox.vleft}

用户安装

随机用户共三万次随机安装

FOR doc IN 1..30000
    LET edge = {_from:(FOR user IN users
                        SORT RAND()
                        LIMIT 1
                        RETURN user)[0]._id,
            _to:(FOR app IN apps
                        SORT RAND()
                        LIMIT 1
                        RETURN app)[0]._id,
            "info":CONCAT("附加信息",doc)}
    INSERT edge INTO installs
    RETURN NEW

{
    "_key": "190139",
    "_id": "installs/190139",
    "_from": "users/24833",
    "_to": "apps/50991",
    "_rev": "_WfLNQbm---",
    "info": "附加信息1"
}

App应用商店关系生成 {:&.flexbox.vleft}

用户卸载

随机用户共三万次随机卸载

FOR doc IN 1..30000
    LET edge = {_from:(FOR user IN users
                        SORT RAND()
                        LIMIT 1
                        RETURN user)[0]._id,
            _to:(FOR app IN apps
                        SORT RAND()
                        LIMIT 1
                        RETURN app)[0]._id,
            "info":CONCAT("附加信息",doc)}
    INSERT edge INTO unstalls
    RETURN NEW
 {
    "_key": "190139",
    "_id": "unstall/190139",
    "_from": "users/24833",
    "_to": "apps/50991",
    "_rev": "_WfLNQbm---",
    "info": "附加信息1"
}  

App应用商店关系生成 {:&.flexbox.vleft}

APP属于某公司

FOR app IN apps
    LET edge = {_from:app._id,
            _to:(FOR com IN company
                        SORT RAND()
                        LIMIT 1
                        RETURN com)[0]._id,
            "info":CONCAT("附加信息",app._key)}
    INSERT edge INTO belongtocompany
    RETURN NEW

 {
    "_key": "190139",
    "_id": "unstall/190139",
    "_from": "users/24833",
    "_to": "apps/50991",
    "_rev": "_WfLNQbm---",
    "info": "附加信息1"
}  

App应用商店关系生成 {:&.flexbox.vleft}

APP属于某分类

FOR app IN apps
    LET edge = {_from:app._id,
            _to:(FOR class IN classify
                        SORT RAND()
                        LIMIT 1
                        RETURN class)[0]._id,
            "info":CONCAT("附加信息",app._key)}
    INSERT edge INTO belongtoclassify
    RETURN NEW

APP属于某分类

APP属于某分类

App应用商店关系生成分析(开发环境) {:&.flexbox.vleft}

二级

测试图

App应用商店关系生成分析(开发环境) {:&.flexbox.vleft}

三级

测试图

App应用商店关系 {:&.flexbox.vleft}

动态推荐APP

与用户相关分类APP,根据安装最多排序

//卸载的APP
LET uninstallapp=( FOR app IN unstalls
    FILTER app._from == @user
    return app)

//安装的APP
LET installapp = ( FOR app IN installs
    FILTER app._from ==@user
    return app)
    
//根据用户安装情况关联未安装的app并且根据安装量排序
FOR v,e,p IN 1..3 OUTBOUND @user installs ,ANY belongtoclassify
FILTER v NOT IN uninstallapp
FILTER v NOT IN installapp
FILTER v IN apps
    FILTER v._id IN installs[*]._to
    COLLECT to = v.id
        WITH COUNT INTO size
        SORT size DESC
        LIMIT 10
        RETURN {
                "app":to,
                "size":size
                }

App应用商店关系生成 {:&.flexbox.vleft}

动态推荐某公司

安装量最多

FOR coll IN  belongtocompany
    FOR app IN apps
        FILTER app._id == coll._from
        FOR install IN installs
            FILTER coll._from == install._to 
            COLLECT appcom = coll._to
                WITH COUNT INTO installsize
                SORT installsize DESC
RETURN {
        size:installsize,
        app:appcom}

App应用商店关系生成 {:&.flexbox.vleft}

动态推荐分类

用户安装app关联分类

FOR classedge IN  belongtoclassify
    FOR app IN apps
        FILTER app._id == classedge._from
        FOR class IN classify
            FILTER class._id == classedge._to 
            COLLECT classifycount = classedge._to
                WITH COUNT INTO installsize
                SORT installsize DESC
RETURN {classify:classifycount,
        size:installsize}

ArangoDB 其他应用体验

Foxx

const createRouter = require('@arangodb/foxx/router');
const indexRouter = createRouter();
indexRouter.all('/', function (req, res) {
  res.redirect('index.html');
});
module.context.use(indexRouter);

点击评论