neo4j语法记录

##################  ##################
#从ownUser.txt中引入两个测试用的假user_cd
###########即replace10######################

match (u:User{user_code:'3125507'}) 
set u.user_code='36006492';
match (u:User{user_code:'821203'}) 
set u.user_code='36006493';
match (u:User{user_code:'3470456'}) 
set u.user_code='36006494';
match (u:User{user_code:'1045896'}) 
set u.user_code='36006495';
match (u:User{user_code:'332679'}) 
set u.user_code='36006496';
#####
match (u:User{user_code:'972803'}) 
set u.user_code='36006497';

match (u:User{user_code:'36006497'}) 
set u.user_code='972803';
match (u:User{user_code:'4265012'}) 
set u.user_code='36006497';
#######
match (u:User{user_code:'365614'}) 
set u.user_code='36006498';


[newnew]记得在rplc10数据库里面先更新点
match (u:User{user_code:'36006498'}) 
set u.user_code=972803;

match (u:User{user_code:'1049763'}) 
set u.user_code='36006498';

##########
match (u:User{user_code:'336479'}) 
set u.user_code='36006499';
match (u:User{user_code:'407286'}) 
set u.user_code='36006500';
match (u:User{user_code:'333646'}) 
set u.user_code='36006501';


##################  ##################
#从ownUser.txt中引入两个测试用的假user_cd
###########即add2######################
# userCode_1: 3213257    
# userCode_2: 4338009
(1) 两个test用的user_cd
using periodic commit
load csv  with headers from 'file:///testUser.csv' as row
create (user:User{user_code:row.user_cd}) 

(2) 为假user_cd 导入search关系
using periodic commit
load csv with headers from 'file:///test_user_kw.csv' as row
match (user:User{user_code:row.user_cd}),(kw:KW{user_input:row.kw})
merge (user)-[r:search{searchtimes:row.searchtimes}]->(kw)
set r.searchtimes=toInteger(row.searchtimes)   #toInteger防止searchtimes列为str类型

(3) 为假user_cd  导入personalClick关系
using periodic commit
load csv with headers from 'file:///test_personal_click.csv' as row
match (user:User{user_code:row.user_cd}),(series:Series_code{series_code:row.series_code})
merge (user)-[r:personalClick {personalKW:row.kw, personalClick:row.personalClickNum}]->(series)
set r.personalClick=toInteger(row.personalClickNum)

###################原始数据库的导入#######################
1. user实体导入
create constraint on (user:User) assert user.user_code is unique

using periodic commit
load csv with headers from 'file:///activeUser.csv' as row
merge (user:User{user_code:row.user_cd})

2.  kw实体导入
create constraint on (kw:KW) assert kw.user_input is unique

using periodic commit
load csv with headers from 'file:///kw15000.csv' as row
merge (kw:KW{user_input:row.kw})

3. series实体导入
CREATE CONSTRAINT ON (series:Series_code) ASSERT series.series_code IS UNIQUE

using periodic commit
load csv with headers from 'file:///series_code.csv' as row
merge (series:Series_code{series_code:row.series_code})

4. 导入relation
# (user:User{user_code:row.user_cd})
# (kw:KW{user_input:row.kw})
# (series:Series_code{series_code:row.series_code})

4.1 user_kw
using periodic commit
load csv with headers from 'file:///user_kw.csv' as row
match (user:User{user_code:row.user_cd}),(kw:KW{user_input:row.kw})
merge (user)-[r:search{searchtimes:row.searchtimes}]->(kw)
set r.searchtimes=toInteger(row.searchtimes)   #toInteger防止searchtimes列为str类型



4.2 kw_series
using periodic commit
load csv with headers from 'file:///kw_series.csv' as row
match (kw:KW{user_input:row.kw}),(series:Series_code{series_code:row.series_code})
merge (kw)-[r:click{clickNum:row.clickNum}]->(series)
set r.clickNum=toInteger(row.clickNum)

4.3 user_series_kw
using periodic commit
load csv with headers from 'file:///personal_click.csv' as row
match (user:User{user_code:row.user_cd}),(series:Series_code{series_code:row.series_code})
merge (user)-[r:personalClick {personalKW:row.kw, personalClick:row.personalClickNum}]->(series)
set r.personalClick=toInteger(row.personalClickNum)


【scenerio 1】的cypher语句
match (u:User)-[r:personalClick]->(series:Series_code) 
where series.series_code in ['110210176309','110300019720','110300026540']
return u.user_code,r.personalKW,r.personalClick,series.series_code limit 26

【scenerio 2】的cypher语句
match (kw:KW)-[r:click]->(series:Series_code) 
where  kw.user_input='轴承' and series.series_code in ['110210176309','110300019720','110300026540']
return kw.user_input, r.clickNum, series.series_code limit 26

【scenerio 3】的cypher语句
match (u:User)-[r:personalClick]->(series:Series_code) 
where u.user_code="1023971" and series.series_code in ['110210176309','110300019720','110300026540']
return u.user_code,r.personalKW,r.personalClick,series.series_code limit 26

【scenerio 4】的cypher语句
match (u:User)-[r:personalClick]->(series:Series_code) 
where r.personalKW='轴承'and series.series_code in ['110210176309','110300019720','110300026540']
return u.user_code,r.personalKW,r.personalClick,series.series_code limit 26


#USING PERIODIC COMMIT #让其自行调整,保证内存不被撑爆
#LOAD CSV with HEADERS from 'file:///sc_n4j.csv' as row
#merge (p1:Product{seriesCode:row.sc1})
#merge (p2:Product{seriesCode:row.sc2})
#merge (p1)-[r:JoinBuyCount]->(p2)
#set r.jointbuycount=toInteger(row.JointBuyCount) # toInteger防止JointBuyCount列为str类型





你可能感兴趣的:(Neo4j)