MATCH inside FOREACH -ish construct in cypher with Neo4j 2.0.1 -
i have neo4j 2.0.1. datastore 10k docs , 12k terms inter-related through 12m rels
(:doc)-[:has_term]->(:term) sometimes need find similar docs, based on count of common terms. specific doc, 3 similar docs retrieved using cypher:
match (d1:doc)-[:has_term]->(t)<-[:has_term]-(d2:doc) d1.id = 'abc123' , d2 <> d1 d1,d2,count(t) commonterms match (d1)-[t1:has_term]->() return d2.id,(commonterms*100/count(t1)) commontermsperc order commontermsperc desc limit 3 works fine, it's expensive. since terms linked docs not change frequently, want create additional relationships between docs similar, like
(:doc)-[:is_similar_to]->(:doc) preferably in periodically executed cypher. of structure (not working cypher because not allow match inside foreach
match (d:doc) collect(d) ds foreach (d1 in ds | match (d1)-[:has_term]->(t)<-[:has_term]-(d2) d1.id = 'abc123' , d2 <> d1 d1,d2,count(t) commonterms match (d1)-[t1:has_term]->() d1,d2,(commonterms*100/count(t1)) commontermsperc order commontermsperc desc limit 3 create (d1)-[:is_similar_to {score:commontermsperc]->(d2) ) the question : can done in cypher?
it seems trying use cypher iterative algorithm on entire graph. called "graph global query". of neo4j 2.0.1, graph global queries not easy in cypher. better if ran messaging queue iterated through each of docs ranking.
this can accomplished performantly using neo4j transactional endpoint. can post multiple cypher statements transaction context.
see reference documentation more details on this:
http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html
Comments
Post a Comment