【问题标题】:how to reinitialize a Neo4j query?如何重新初始化 Neo4j 查询?
【发布时间】:2015-08-25 14:44:22
【问题描述】:

您能否告诉我哪个命令行可以帮助我重新初始化 neo4j 查询,解释更多,我有一个查询提供所有用户节点,第二个查询提供文件夹节点,不幸的是,第二个查询记住结果第一个查询。

编辑 0

以下是 OP 作为答案发布的附加信息的串联。对于有能力的人,请合并编辑并删除此评论。

编辑 1

            <td>
            <select name=user>
            <?php
            $result1 = $client->sendCypherQuery("MATCH (n:$label1) return n")->getResult();
            $i=0;
            foreach ($result1->getNodes() as $nu){

                $n[$i]=$nu->getproperty('lastname');
                $i++;
            }
                while ($j<$i)
                {
                echo "<option value='$n[$j]'> $n[$j] </option>";
                $j=$j+1;
                }
                echo "</select>";

            ?>
            </td>
        </tr>
        <tr>
            <td>Nom dossier :</td>
            <td>
            <select name=folder>
            <?php
            $result2 = $client->sendCypherQuery("MATCH (n:$label2) return n")->getResult();
            $i=0;
            foreach ($result2->getNodes() as $nd){

                $d[$i]=$nd->getProperty('name');
                $i++;
            }
            $j=0;
                while ($j<$i)
                {
                echo "<option value='$d[$j]'> $d[$j] </option>";
                $j=$j+1;
                }
                echo "</select>";
            ?>
            </td>
        </tr>

编辑 2

我有 2 个用户和 2 个文件夹。 $result1 应该返回用户,$result2 应该返回文件夹。 当我查找文件夹的大小时,我得到 4 而不是 2,因此查询始终记住第一个查询的结果。

编辑 3

var_dump($result1),我明白了:

object(Neoxygen\NeoClient\Formatter\Result)  protected 'nodes' => 
array (size=2)
  7 => 
    object(Neoxygen\NeoClient\Formatter\Node)[796]
      protected 'id' => string '7' (length=1)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=6)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...
  9 => 
    object(Neoxygen\NeoClient\Formatter\Node)[797]
      protected 'id' => string '9' (length=1)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=6)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...   protected 'relationships' => 
array (size=0)
  empty   protected 'errors' => null 
  protected 'identifiers' => 
array (size=1)
  'n' => 
    array (size=2)
      0 => 
        object(Neoxygen\NeoClient\Formatter\Node)[796]
          ...
      1 => 
        object(Neoxygen\NeoClient\Formatter\Node)[797]
          ...

编辑 4

var_dump($result2):

object(Neoxygen\NeoClient\Formatter\Result)  protected 'nodes' => 
array (size=4)
  7 => 
    object(Neoxygen\NeoClient\Formatter\Node)[799]
      protected 'id' => string '7' (length=1)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=6)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...
  9 => 
    object(Neoxygen\NeoClient\Formatter\Node)[800]
      protected 'id' => string '9' (length=1)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=6)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...
  8 => 
    object(Neoxygen\NeoClient\Formatter\Node)[787]
      protected 'id' => string '8' (length=1)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=2)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...
  10 => 
    object(Neoxygen\NeoClient\Formatter\Node)[788]
      protected 'id' => string '10' (length=2)
      protected 'labels' => 
        array (size=1)
          ...
      protected 'properties' => 
        array (size=2)
          ...
      protected 'inboundRelationships' => 
        array (size=0)
          ...
      protected 'outboundRelationships' => 
        array (size=0)
          ...

编辑 5

<?php    include 'connection.php'; 
$j=0;

$l=0;

$label1="user";

$label2="folder1";

?>
<br><br><br>    
<h3>Ajouter relation</h3>    
<form action='php/addlink.php' method=post>
    <table>
        <tr>
            <td>Nom utilisateur:</td>
            <td>
            <select name=user>
            <?php
            $result1 = $client->sendCypherQuery("MATCH (n:$label1) return n")->getResult();

            $i=0;
            foreach ($result1->getNodes() as $nu){

                $n[$i]=$nu->getproperty('lastname');
                $i++;
            }
                while ($j<$i)
                {
                echo "<option value='$n[$j]'> $n[$j] </option>";
                $j=$j+1;
                }
                echo "</select>";

            ?>
            </td>
        </tr>
        <tr>
            <td>Nom dossier :</td>
            <td>
            <select name=folder>
            <?php
            $result2 = $client->sendCypherQuery("MATCH (n:$label2) return n")->getResult();

            $i=0;
            foreach ($result2->getNodes() as $nd){

                $d[$i]=$nd->getid();
                $i++;
            }
            $j=0;
                while ($j<$i)
                {
                echo "<option value='$d[$j]'> $d[$j] </option>";
                $j=$j+1;
                }
                echo "</select>";
            ?>

【问题讨论】:

  • 请发布查询。他们的结果是什么?你期待什么?
  • 问题是:$d[$j] 返回第一个查询的结果,也是第二个查询的结果
  • 请将查询作为问题的一部分发布,而不是在小 cmets 中。它几乎不可读,尤其是在移动设备上
  • Amina 这些查询仅在 $label1$label2 上有所不同。这些价值观是什么?如果它们相同,则返回相同内容的查询是有意义的。
  • @Aminael,如果您希望有人帮助您解决问题,您将需要花时间了解 StackOverflow 的工作原理。特别是,您需要编辑您的问题以添加更多信息。您提供的答案不是答案,现在对于试图阅读您的问题并帮助您的人来说非常混乱。希望您仍然可以解决您的问题,但是为了将来获得运动机会,您将需要花时间学习使用 StackOverflow。

标签: php neo4j neoxygen


【解决方案1】:

这真的很奇怪,我创建了一个集成测试,证明结果在后续查询中不会重复:

https://github.com/neoxygen/neo4j-neoclient/blob/master/tests/Neoxygen/NeoClient/Tests/Issues/IssueSOResultDuplicationTest.php

所以我会看不同的位置:

  1. 确保只有 2 个文件夹节点
  2. 检查所有变量是否都已重新初始化
  3. 查询中提供的标签

注意:您可以编辑原始问题,而不是创建多个回复。

我已经测试了你的代码,只是用我的数据库中的标签替换了标签,我只得到了 2 个文件夹:

所以我会检查数据库内容,你可以尝试在浏览器中手动进行第二次查询吗?

【讨论】:

    猜你喜欢
    • 2016-06-26
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 2021-11-06
    • 2013-03-27
    • 1970-01-01
    相关资源
    最近更新 更多