Hey Tom, The query execution plan of your Cypher statement is cached after you run the query for the first time. It's important that you remember to format your Cypher queries with parameters using the REST API.
For instance, match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) where NOT (id(j1)=id(j2)) AND j1.jurt_id = {id} with j1,j2,count(t) as commonterms return j1.jurt_id,j2.jurt_id,commonterms order by commonterms desc limit 3 I've added a parameter for the ID in your WHERE clause. When you POST to the REST API, make sure you supply a JSON key-value for the name of the parameter within the curly braces. By doing this, the Cypher execution plan can be cached because the text of the statement remains the same minus the parameter. When you do not supply parameters, you'll take a hit every time you run a different query. Cheers, Kenny On Friday, March 7, 2014 5:02:29 PM UTC-5, Tom Zeppenfeldt wrote: > > I have a graph db with about 10000 docs (:jurt) and about 12000 terms > (t:Term) from a vocabulary. There are about 1.2M relationships of type > (j:jurt)-[:HAS_TERM]->(t:Term) > > To find out which documents are similar to a given document, based on a > count of common terms, I use this query > > match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) > where NOT (id(j1)=id(j2)) AND j1.jurt_id = 'J75312' > with j1,j2,count(t) as commonterms > return j1.jurt_id,j2.jurt_id,commonterms > order by commonterms desc > limit 3 > > What I notice is that the first time the query is run, the results are > different from the next times... from the second time onwards, the results > are the same. In between, there are no other processes running.. > Whether I run the queries from the browser, the shell or the REST API, > they all show the same phenomenon. > > neo4j-sh (?)$ match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) > where NOT (id(j1)=id(j2)) AND j1.jurt_id = 'J72887' with j1,j2,count(t) as > commonterms return j1.jurt_id,j2.jurt_id,commonterms order by commonterms > desc limit 3; > > +---------------------------------------+ > > | j1.jurt_id | j2.jurt_id | commonterms | > > +---------------------------------------+ > > | "J72887" | "J70059" | 226 | > > | "J72887" | "J75312" | 220 | > > | "J72887" | "J77444" | 215 | > > +---------------------------------------+ > > 3 rows > > 6288 ms > > neo4j-sh (?)$ match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) > where NOT (id(j1)=id(j2)) AND j1.jurt_id = 'J72887' with j1,j2,count(t) as > commonterms return j1.jurt_id,j2.jurt_id,commonterms order by commonterms > desc limit 3; > > +---------------------------------------+ > > | j1.jurt_id | j2.jurt_id | commonterms | > > +---------------------------------------+ > > | "J72887" | "J70059" | 227 | > > | "J72887" | "J75312" | 220 | > > | "J72887" | "J77444" | 219 | > > +---------------------------------------+ > > 3 rows > > 6299 ms > > neo4j-sh (?)$ match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) > where NOT (id(j1)=id(j2)) AND j1.jurt_id = 'J72887' with j1,j2,count(t) as > commonterms return j1.jurt_id,j2.jurt_id,commonterms order by commonterms > desc limit 3; > > +---------------------------------------+ > > | j1.jurt_id | j2.jurt_id | commonterms | > > +---------------------------------------+ > > | "J72887" | "J70059" | 227 | > > | "J72887" | "J75312" | 220 | > > | "J72887" | "J77444" | 219 | > > +---------------------------------------+ > > 3 rows > > 6354 ms > > neo4j-sh (?)$ match (j1:jurt)-[:HAS_TERM]->(t:Term)<-[:HAS_TERM]-(j2:jurt) > where NOT (id(j1)=id(j2)) AND j1.jurt_id = 'J72887' with j1,j2,count(t) as > commonterms return j1.jurt_id,j2.jurt_id,commonterms order by commonterms > desc limit 3; > > +---------------------------------------+ > > | j1.jurt_id | j2.jurt_id | commonterms | > > +---------------------------------------+ > > | "J72887" | "J70059" | 227 | > > | "J72887" | "J75312" | 220 | > > | "J72887" | "J77444" | 219 | > > +---------------------------------------+ > > 3 rows > > 6108 ms > > > What may cause this ? > -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.