Limit Clause Neo4jClient - neo4jclient

I am trying to implement the Limit clause in Cypher in Neo4jClient but it doe not seem to be supported (?).
I thought I saw some test cases / other documents refer to it but I can't seem to find it in my intellisense.
Is there a work around to limit results to only top 5? I have 5000+ results and results are painfully slow.
I am using Neo4jClient version 1.0.0.572. Many thanks!

The tests that you pointed to clearly indicate that it exists, and works, and is supported, and tested.
Without having posted your query, I can only guess at the problem.
The Limit method only shows up after you've called Return, because it's defined on ICypherFluentQuery<TResults>, not ICypherFluentQuery.

Related

Weird results from cypher collaborative filter query

I am using one of the neo4j practice graphs (see below) to learn cypher
and running a query to search for people who both acted int and directed a movie, I'm running the following commands:
:play movie graph
MATCH (p:Person)-[a:ACTED_IN]->(m:Movie)<-[d:DIRECTED]-(p)
RETURN p,m,a,d,type(a),type(d)
I few things don't make sense:
for some rows in the result type(a) is not ACTED_IN but
PRODUCER or WROTE etc.
a lot of nodes are returned which don't seem to satisfy this pattern
using OPTIONAL MATCH works exactly right but I don't know why?
Any help would be much appreciated
As cybersam commented, this definitely looks like a bug in the compiled runtime.
If you PROFILE this you can see it's using compiled runtime; if you prefix the query with CYPHER runtime=slotted we get expected results.
I'll pass this along to the cypher team.

cypher query with apoc.path.subgraphAll , it seems limit config is not working

I am executing following query:
MATCH (e:COMP) WHERE e.componentID= "f4db22e7-68d2-473d-960b-c98dbbadb3a0"
with e limit 1 CALL apoc.path.subgraphAll(e,
{relationshipFilter:'CHILD_OF|CONNECTED_TO|LINKED_TO', limit:10}) YIELD nodes
UNWIND nodes as node RETURN node.componentID as uuid, node.orphanID as oid,
node.cTime as time
I was expecting that i will get 10 rows but I am getting more than 300 rows. Not sure if I am missing something here?
Actually in my graph there can be 100,000 nodes related with these relationship (CHILD_OF,CONNECTED_TO,LINKED_TO). In that case I just want to limit result to 1000.
Figured this out on the neo4j-users slack.
This was being executed with APOC 3.2.3.5, where the limit config parameter was only being utilized when there was a labelFilter using end-node or terminator-node filters. This was noted in the documentation for the previous version.
With APOC 3.2.3.6 (and 3.3.0.2) limit now applies in all cases, no matter what filters are used and even without using the label filter.
While the lines in the documentation referencing the restriction were removed with the latest release, this isn't enough. The change itself (and behavior before the change) needs to be added to the documentation.

Can "DISTINCT" in a CYPHER query be responsible of a memory error when the query returns no result?

working on a pretty small graph of 5000 nodes with low density (mean connectivity < 5), I get the following error which I never got before upgrading to neo4j 3.3.0. The graph contains 900 molecules and their scaffold hierarchy, down to 5 levels.
(:Molecule)<-[:substructureOf*1..5]-(:Scaffold)
Neo.TransientError.General.StackOverFlowError
There is not enough stack size to perform the current task. This is generally considered to be a database error, so please contact Neo4j support. You could try increasing the stack size: for example to set the stack size to 2M, add `dbms.jvm.additional=-Xss2M' to in the neo4j configuration (normally in 'conf/neo4j.conf' or, if you are using Neo4j Desktop, found through the user interface) or if you are running an embedded installation just add -Xss2M as command line flag.
The query is actually very simple, I use distinct because several path may lead to a single scaffold.
match (m:Molecule) <-[:substructureOf*3]- (s:Scaffold) return distinct s limit 20
This query returns the above error message whereas the next query does work.
match (m:Molecule) <-[:substructureOf*3]- (s:Scaffold) return s limit 20
Interestingly, the query works on a much larger database, in this small one the deepest hierarchy happened to be 2. Therefore the result of the last query is "No changes, no records)".
How comes that adding DISTINCT to the query fails with that memory error? Is there a way to avoid it, because I cannot guess the depth of the hierarchy which can be different for each molecules.
I tried the following values for as suggested in other posts.
#dbms.memory.heap.initial_size=512m
#dbms.memory.heap.max_size=512m
dbms.memory.heap.initial_size=512m
dbms.memory.heap.max_size=4096m
dbms.memory.heap.initial_size=4096m
dbms.memory.heap.max_size=4096m
None of these addressed the issue.
Thanks in advance for any help or clues.
Thanks for the additional info, I was able to replicate this on Neo4j 3.3.0 and 3.3.1, and this likely has to do with the behavior of the pruning-var-expand operation (that is meant to help when using variable-length expansions and distinct results) that was introduced in 3.2.x, and only when using an exact number of expansions (not a range). Neo4j engineering will be looking into this.
In the meantime, your requirement is such that we can use a different kind of query to get the results you want that should avoid this operation. Try giving this one a try:
match (s:Scaffold)
where (s)-[:substructureOf*3]->(:Molecule)
return distinct s limit 20
And if you do need to perform queries that may produce this error, you may be able to circumvent them by prepending your query with CYPHER 3.1, which will execute this with a plan produced by an older version of Cypher which doesn't use the pruning var expand operation.

Weird results with cypher query in Neo4j and node_auto_index

I have a graph database (Neo4j) in which I configured a property to be auto indexed with full-text. Everything is working great except that I have 1 row that is not returned when I execute a particular cypher query.
My property in the graph equals (I've put in bold the words I am using in my cypher query):
1pizzeriadeicomparipourlesamateursdevraiespizzasitaliennescestadireavecpastropdepateetcuitesaufeudeboislaplacenepayepasdeminesalleettablesassezpetitesetilfautsarmerdepatiencelessamedisoirssionnapasreserveenv15minutesdattentemaislespizzassontexcellentesrestaurantmontrealmontrealquebeccanada5148435411
If I execute the following cypher query:
START n1=NODE:node_auto_index('Search_Field:*res* AND Search_Field:*taurant* AND Search_Field:*411*')
RETURN n1.Search_Field
My row is returned!
So far no problem!
But when I execute it by putting the word « restaurant » all together like this:
START n1=NODE:node_auto_index('Search_Field:*restaurant* AND Search_Field:*411*')
RETURN n1.Search_Field
Then no rows are returned.
I tested a lot of stuffs in order to understand and try to find a pattern or something that can explain the problem. It seems like the length of my property value might play a role. I know it sounds strange but if I add 3 or more letters, let say « aaa », after the word restaurant in the property value, like this (look at the bold letters close to the end of the value):
1pizzeriadeicomparipourlesamateursdevraiespizzasitaliennescestadireavecpastropdepateetcuitesaufeudeboislaplacenepayepasdeminesalleettablesassezpetitesetilfautsarmerdepatiencelessamedisoirssionnapasreserveenv15minutesdattentemaislespizzassontexcellentesrestaurantaaamontrealmontrealquebeccanada5148435411
then, if I execute the same cypher query, the row is now returned.
Anyone had encountered similar problems! It's driving me crazy!
I have tested on both Neo4j-enterprise 2.2.1 and the latest Community 3.0.0-M02. Same result with both of them.
Any idea on where or what should I look for ?
The query term get passed through the lucene analyzer - just like the contents you index. I'm not 100% sure but I think that the default analyzer "eats up" the digits, that's why you don't get the results.
You can supply an analyzer class when the index is created for the first time. Also you can use Java API to query the index - this allows to pass in instances of Lucene Query, see my example at http://blog.armbruster-it.de/2014/10/deep-dive-on-fulltext-indexing-with-neo4j/.

Realm GROUP BY query

I've searched a lot but can't find any documantation or an example for GROUP BY queries.
For now, even putting RLMResults in a loop can solve my problem but is there an elegant way to get?
It was discussed at the Java group and also applies for the iOS implementation.
Nov 2014
GROUP BY is only interesting in combination with some kind of
aggregate function. We have the most common ones directly on
RealmResults, like sum(), average(), max() and min(), are these what
you are looking for or do you have something else in mind?
We actually implemented DISTINCT but found some bugs that needed to be
fixed before it can be released. So hopefully really soon :)
The distinct operation is yet not available but there is an easy workaround for it.
Oct 2015
DISTINCT made progress in core, but isn't yet fully implemented and
wasn't so exposed yet neither in the Java binding nor in any other.
We're working on that and will make sure to report back here once we
have something to test out.
Regarding examples, the official docs have one:
The aggregate expressions #count, #min, #max, #sum and #avg are
supported on RLMArray properties, e.g.
[Company objectsWhere:#"employees.#count > 5"] to find all companies with more
than five employees.

Resources