Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion cypher query to connect a where clause with the elements of an array

Received: by 10.14.204.3 with SMTP id g3mr9330090eeo.7.1352396407468;
        Thu, 08 Nov 2012 09:40:07 -0800 (PST)
X-BeenThere: neo4j@googlegroups.com
Received: by 10.14.173.67 with SMTP id u43ls2289322eel.8.gmail; Thu, 08 Nov
 2012 09:39:56 -0800 (PST)
Received: by 10.14.199.6 with SMTP id w6mr9349599een.0.1352396396798;
        Thu, 08 Nov 2012 09:39:56 -0800 (PST)
Received: by 10.14.199.6 with SMTP id w6mr9349597een.0.1352396396770;
        Thu, 08 Nov 2012 09:39:56 -0800 (PST)
Return-Path: <freeman....@gmail.com>
Received: from mail-ee0-f48.google.com (mail-ee0-f48.google.com [74.125.83.48])
        by gmr-mx.google.com with ESMTPS id z47si5432327eel.0.2012.11.08.09.39.56
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 08 Nov 2012 09:39:56 -0800 (PST)
Received-SPF: pass (google.com: domain of freeman....@gmail.com designates 74.125.83.48 as permitted sender) client-ip=74.125.83.48;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of freeman....@gmail.com designates 74.125.83.48 as permitted sender) smtp.mail=freeman....@gmail.com; dkim=pass header...@gmail.com
Received: by mail-ee0-f48.google.com with SMTP id b45so1901219eek.35
        for <neo4j@googlegroups.com>; Thu, 08 Nov 2012 09:39:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :content-type;
        bh=k3EPjDXtSyl3Ix/k8jMTXBo3KEV4++rsFYWW+/nsThQ=;
        b=WjLa+f5i/qIzN/N7CkAaJCouyA/5OvPw9nOkinhxzpOmLbtLcOVADwBP42rC/5ho47
         Wi3cSUCIsZPtFIH40njr6gE2K4JOf1JF+LzmNHCRJWqco0vIMUkf4GlAjL0pAa1IO+Q7
         4mbFucF0hc/wnPfi4MrtAr7WQphi+cjlBph9NaQpCtWWsGlV+WoNMbBmqego4CmjBJeW
         q/z1bAQU43F6YweHTpZOSDDNjV3mvS+asfTufrUdmuRqDG4wWQWNgZirYrhMMwZ6vdSj
         xyD5NqQIHrECSFVy/uATSlmgfdrh2sK+aLkg87YppdNLYqrZiphxRBJlkpGFouGODyPi
         2K5w==
Received: by 10.14.175.71 with SMTP id y47mr29488913eel.36.1352396395828; Thu,
 08 Nov 2012 09:39:55 -0800 (PST)
MIME-Version: 1.0
Received: by 10.223.150.138 with HTTP; Thu, 8 Nov 2012 09:39:35 -0800 (PST)
In-Reply-To: <a8d34a47-057b-4b5e-ae3b-e0eb1db27ae4@googlegroups.com>
References: <7b4f7d5e-7f1d-4a7d-a93f-9e840a88aa86@googlegroups.com>
 <CAAOkgHMLHXePFADo7RQQFdugXEHeuaNeXyo=Gf69jCs0ROE...@mail.gmail.com>
 <CAAOkgHPW0TXdtNwvYwp7G7vSeaATbVDseaukrZtWKnyN3+N...@mail.gmail.com>
 <f8a6dacf-a1f5-4eda-bf1c-dc24e1a00502@googlegroups.com> <be1f9e15-8c04-4a42-a419-9063cfb5046a@googlegroups.com>
 <CAAOkgHN0w_ZLfch6=nFyYUxHBYtnNtDrM1jrMLyne8fe9AK...@mail.gmail.com>
 <baa21a00-9ed5-43ad-a995-6108992d8f30@googlegroups.com> <CAAOkgHOWUg6sGbQrsCRmEYu8kyHmoVkqc=_BeTZAw14mNoA...@mail.gmail.com>
 <155260dc-344c-4ab2-ab1d-c679a1605124@googlegroups.com> <CAAOkgHN9e47K9TxrpXEjtjFbv5hG0jnsdBJB5gtYoWGw+z7...@mail.gmail.com>
 <a8d34a47-057b-4b5e-ae3b-e0eb1db27ae4@googlegroups.com>
From: Wes Freeman <freeman....@gmail.com>
Date: Thu, 8 Nov 2012 12:39:35 -0500
Message-ID: <CAAOkgHO-TEG8UZy53Ncp4+eomSU1SrcTaUBz6zw70YKwFk=...@mail.gmail.com>
Subject: Re: [Neo4j] cypher query to connect a where clause with the elements
 of an array
To: neo4j@googlegroups.com
Content-Type: multipart/alternative; boundary=047d7b603e96c4da6304cdff52d8

--047d7b603e96c4da6304cdff52d8
Content-Type: text/plain; charset=UTF-8

They have an example there with a parameter using the constructor...

$queryString = "start n=node(*) ".    "match n-[:rel]->() ".    "where
not(n.prop in {phparr}) ".    "return n";$query = new
Everyman\Neo4j\Cypher\Query($client, $queryString, array('phparr' =>
$result_array));$result = $query->getResultSet();

I'm assuming it knows how to convert a php array to a json array, but maybe
that's not a good assumption. If it doesn't, you might have to do something
like http://php.net/manual/en/function.json-encode.php to convert your php
array to a json non-associative array.


On Thu, Nov 8, 2012 at 12:25 PM, divyanshu das <divyanshu....@gmail.com>wrote:

> I am using cypher queries as mentioned in
> https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-queries
>
> my phparray is $result_array, so will the query look like this?
>
> $queryTemplate = "START n = node(*) MATCH n-[:rel]->() WHERE not(n.prop in
> {phparr}) Return n", params:{phparra:$result_array};
>
>
> On Thursday, 8 November 2012 22:47:42 UTC+5:30, Wes Freeman wrote:
>
>> You can also specify a literal array in cypher... not sure what you're
>> using from PHP, but you can do something like this via REST:
>> {query:"start n=node(*)
>> match n-[:rel]->()
>> where not(n.prop in {phparr})
>> return n;", params:{phparr:[1,2,3]}}
>>
>> On Thu, Nov 8, 2012 at 11:55 AM, divyanshu das <divyan...@gmail.com>wrote:
>>
>>> @Freeman, The code that you gave works for array when it is in neo4j.
>>>
>>> I have a separate php array that I am fetching from mysql.
>>>
>>> I need to delete the nodes and relationships for nodes whose certain
>>> property matches the values stored in thee array.
>>>
>>>
>>> On Thursday, 8 November 2012 03:23:19 UTC+5:30, Wes Freeman wrote:
>>>
>>>> Well, I think the REST delete commands existed in 1.6 if you're using
>>>> server. If you're using embedded, you can do it like this:
>>>> http://docs.neo4j.org/chunked/****stable/tutorials-java-**embedded**
>>>> -hello-world.html#_**remove_the_**data<http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-hello-world.html#_remove_the_data>
>>>>
>>>> On Wed, Nov 7, 2012 at 4:36 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>
>>>>> Is there any other way to delete nodes in 1.6.1 without using cypher
>>>>> queries?
>>>>>
>>>>>
>>>>> On Thursday, 8 November 2012 02:56:56 UTC+5:30, Wes Freeman wrote:
>>>>>
>>>>>> It isn't a good idea to depend on node ids for long term use (rather,
>>>>>> use an email address or guid or similar unique id, with an index). Ids are
>>>>>> reused after you restart the server, I think, if they were deleted.
>>>>>>
>>>>>> Wes
>>>>>>
>>>>>>
>>>>>> On Wed, Nov 7, 2012 at 4:18 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>>>
>>>>>>> If I upgrade to 1.8, then I get the delete queries. Now, If I delete
>>>>>>> the nodes, will the node ids for other users remain unchanged or neo4j
>>>>>>> automatically reuses the deleted ids?
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das wrote:
>>>>>>>>
>>>>>>>> Hey, thanks for prompt replies. If I am correct, node(*) method is
>>>>>>>> not available in 1.6.1. Any workaround  for this?
>>>>>>>>
>>>>>>>> On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman wrote:
>>>>>>>>>
>>>>>>>>> I guess that's not exactly what you asked for... how about this:
>>>>>>>>>
>>>>>>>>> http://console.neo4j.org/r/**xg5******y9u<http://console.neo4j.org/r/xg5y9u>
>>>>>>>>>
>>>>>>>>> start n=node(*)
>>>>>>>>> match n-[:rel]->()
>>>>>>>>> where has(n.arr) and not(n.prop in n.arr)
>>>>>>>>> return n;
>>>>>>>>>
>>>>>>>>> On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <freem...@gmail.com>wrote:
>>>>>>>>>
>>>>>>>>>> You can't delete via Cypher with that version of Neo.
>>>>>>>>>>
>>>>>>>>>> If you want to just find them, you could do something like (I'm
>>>>>>>>>> not entirely sure this worked back then, either--you might consider
>>>>>>>>>> upgrading):
>>>>>>>>>>
>>>>>>>>>> start n=node(*)
>>>>>>>>>> where n.prop in n.arr
>>>>>>>>>> return n;
>>>>>>>>>>
>>>>>>>>>> Wes
>>>>>>>>>>
>>>>>>>>>> On Wed, Nov 7, 2012 at 3:43 PM, divyanshu das <
>>>>>>>>>> divyan...@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> I have neo4j 1.6.1 and I am using php .
>>>>>>>>>>>
>>>>>>>>>>> I have an array "arr" of a particular property "prop" of nodes.
>>>>>>>>>>>
>>>>>>>>>>> I want to delete all nodes from neo4j having a certain
>>>>>>>>>>> relationship "rel" except for the nodes whose property "prop" is in the
>>>>>>>>>>> array "arr".
>>>>>>>>>>>
>>>>>>>>>>> Can somebody help me out with this?
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>  --
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>>
>>>
>>>
>>
>>  --
>
>
>

--047d7b603e96c4da6304cdff52d8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

They have an example there with a parameter using the constructor...<div><p=
re style=3D"margin-top:15px;margin-bottom:15px;padding:6px 10px;border:1px =
solid rgb(204,204,204);font-size:13px;font-family:Consolas,&#39;Liberation =
Mono&#39;,Courier,monospace;background-color:rgb(248,248,248);line-height:1=
9px;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;bo=
rder-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,=
51)">

<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">$queryString =
=3D &quot;start n=3Dnode(*) &quot;.</span>
<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">    &quot;matc=
h n-[:rel]-&gt;() &quot;.</span>
<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">    &quot;wher=
e not(n.prop in {phparr}) &quot;.</span>
<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">    &quot;retu=
rn n&quot;;</span>
<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">$query =3D new=
 Everyman\Neo4j\Cypher\Query($client, $queryString, array(&#39;phparr&#39; =
=3D&gt; $result_array));</span>
<span class=3D"" style=3D"margin:0px;padding:0px;border:0px">$result =3D $q=
uery-&gt;getResultSet();</span></pre><div class=3D"gmail_extra">I&#39;m ass=
uming it knows how to convert a php array to a json array, but maybe that&#=
39;s not a good assumption. If it doesn&#39;t, you might have to do somethi=
ng like=C2=A0<a href=3D"http://php.net/manual/en/function.json-encode.php">=
http://php.net/manual/en/function.json-encode.php</a> to convert your php a=
rray to a json non-associative array.</div>

<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra"><br><div cl=
ass=3D"gmail_quote">On Thu, Nov 8, 2012 at 12:25 PM, divyanshu das <span di=
r=3D"ltr">&lt;<a href=3D"mailto:divyanshu....@gmail.com" target=3D"_blank">=
divyanshu....@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">I am using cypher queries as mentioned in=C2=A0<a href=3D"=
https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-queries" target=
=3D"_blank">https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-quer=
ies</a><div>

<br></div><div>my phparray is $result_array, so will the query look like th=
is?</div><div><br></div><div>$queryTemplate =3D &quot;START n =3D node(*) M=
ATCH n-[:rel]-&gt;() WHERE not(n.prop in {phparr}) Return n&quot;, params:{=
phparra:$result_array};</div>

<div><div class=3D"im"><br><br>On Thursday, 8 November 2012 22:47:42 UTC+5:=
30, Wes Freeman  wrote:</div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,2=
04);border-left-style:solid;padding-left:1ex">

<div class=3D"im">You can also specify a literal array in cypher... not sur=
e what you&#39;re using from PHP, but you can do something like this via RE=
ST:</div><div><div class=3D"im">{query:&quot;<span style=3D"color:rgb(80,0,=
80)">start n=3Dnode(*)=C2=A0</span><div style=3D"color:rgb(80,0,80)">



match n-[:rel]-&gt;()=C2=A0</div><div style=3D"color:rgb(80,0,80)">where no=
t(n.prop in {phparr})=C2=A0</div><div style=3D"color:rgb(80,0,80)">return n=
;&quot;,=C2=A0params:{phparr:[1,2,3]}}</div></div><div><div class=3D"h5"><d=
iv><br><div class=3D"gmail_quote">



On Thu, Nov 8, 2012 at 11:55 AM, divyanshu das <span dir=3D"ltr">&lt;<a>div=
yan...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:=
rgb(204,204,204);border-left-style:solid;padding-left:1ex">



@Freeman, The code that you gave works for array when it is in neo4j.<div><=
br></div><div>I have a separate php array that I am fetching from mysql.</d=
iv><div><br></div><div>I need to delete the nodes and relationships for nod=
es whose certain property matches the values stored in thee array.<div>



<br><br>On Thursday, 8 November 2012 03:23:19 UTC+5:30, Wes Freeman  wrote:=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:s=
olid;padding-left:1ex">



<div><div>Well, I think the REST delete commands existed in 1.6 if you&#39;=
re using server. If you&#39;re using embedded, you can do it like this:<br>=
<a href=3D"http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-hel=
lo-world.html#_remove_the_data" target=3D"_blank">http://docs.neo4j.org/chu=
nked/<u></u><u></u>stable/tutorials-java-<u></u>embedded<u></u>-hello-world=
.html#_<u></u>remove_the_<u></u>data</a><br>





</div><br></div><div><div><div><div class=3D"gmail_quote">On Wed, Nov 7, 20=
12 at 4:36 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...@gmail.com</=
a>&gt;</span> wrote:<br>


<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">Is there any other way to delete nodes in 1.6.1 without us=
ing cypher queries?<div>





<br><br>On Thursday, 8 November 2012 02:56:56 UTC+5:30, Wes Freeman  wrote:=
</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div>It isn&#39;t a good idea to depend on node ids for lo=
ng term use (rather, use an email address or guid or similar unique id, wit=
h an index). Ids are reused after you restart the server, I think, if they =
were deleted.<div>






<br>

</div></div><div>Wes<div><div><br><div><br><div class=3D"gmail_quote">On We=
d, Nov 7, 2012 at 4:18 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...=
@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">If I upgrade to 1.8, then I get the delete queries. Now, I=
f I delete the nodes, will the node ids for other users remain unchanged or=
 neo4j automatically reuses the deleted ids?<div>








<div><br><br>On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das =
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;=
border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:=
solid;padding-left:1ex">





Hey, thanks for prompt replies. If I am correct, node(*) method is not avai=
lable in 1.6.1. Any workaround =C2=A0for this?<br>


<br>On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman  wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left=
-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;paddi=
ng-left:1ex">





<div>I guess that&#39;s not exactly what you asked for... how about this:<b=
r>


<br></div><div><a href=3D"http://console.neo4j.org/r/xg5y9u" target=3D"_bla=
nk">http://console.neo4j.org/r/<u></u>xg5<u></u><u></u><u></u>y9u</a><br></=
div><div><br></div><div><div>start n=3Dnode(*)=C2=A0</div>

<div>match n-[:rel]-&gt;()=C2=A0</div><div>where has(n.arr) and not(n.prop =
in n.arr)=C2=A0</div><div>return n;</div></div><br><div><div class=3D"gmail=
_quote">On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <span dir=3D"ltr">&lt;<=
a>freem...@gmail.com</a>&gt;</span> wrote:<br>










<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">You can&#39;t delete via Cypher with that version of Neo.=
=C2=A0<div>










<br></div><div>If you want to just find them, you could do something like (=
I&#39;m not entirely sure this worked back then, either--you might consider=
 upgrading):</div>
<div><br>start n=3Dnode(*)<br>where n.prop in n.arr<br>return n;<br><div><b=
r></div><div>Wes</div><div><div><div><br><div class=3D"gmail_quote">On Wed,=
 Nov 7, 2012 at 3:43 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...@g=
mail.com</a>&gt;</span> wrote:<br>











<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div>I have neo4j 1.6.1 and I am using php .</div><div><br=
>










</div>I have an array &quot;arr&quot; of a particular property &quot;prop&q=
uot; of nodes.<div>
<br></div><div>I want to delete all nodes from neo4j having a certain relat=
ionship &quot;rel&quot; except for the nodes whose property &quot;prop&quot=
; is in the array &quot;arr&quot;.</div><div><br></div><div>Can somebody he=
lp me out with this?=C2=A0</div>











<span><font color=3D"#888888">

<p></p>

-- <br>
=C2=A0<br>
=C2=A0<br>
</font></span></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</blockquote></blockquote>

<p></p>

-- <br>
=C2=A0<br>
=C2=A0<br>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote>

<p></p>

-- <br>
=C2=A0<br>
=C2=A0<br>
</blockquote></div><br></div>
</div></div></blockquote></div>

<p></p>

-- <br>
=C2=A0<br>
=C2=A0<br>
</blockquote></div><br></div></div></div></div>
</blockquote></div>

<p></p>

-- <br>
=C2=A0<br>
=C2=A0<br>
</blockquote></div><br></div></div>

--047d7b603e96c4da6304cdff52d8--