1

关于为我们创建的节点创建索引我有一个问题..

如果我从 MySql 迁移到 neo4j graph db,我必须为每条记录创建一个索引还是可以在最后创建?

PS:对不起,我是新手,我正在努力学习这个愚蠢的问题。这是代码:` $query = 'SELECT * FROM product'; $result = mysql_query ($query);

while ( $row = mysql_fetch_array ($result) ) {
    $product = $this->client->makeNode ();
    $product->setProperty ('product_id',(int)$row[ 'product_id' ])
        ->setProperty ('sku', $row[ 'sku' ])
        ->save ();
    $productIndex =  new NodeIndex($this->client,'products');
    $productIndex->save();
    $productLabel = $this->client->makeLabel ('product');
    $product->addLabels (array ( $productLabel ));

    echo "Done creating " . $row[ 'product_id' ] . " node<br/>";

}`

我也想知道我如何看到索引是创建的(在浏览器中)或者我看不到它只是感觉到它?谢谢 !

4

2 回答 2

1

您需要创建一次索引

$productIndex = new NodeIndex($this->client,'products'); $productIndex->​​保存();

然后将节点添加到索引中

$productIndex>add($node, 'key', 'value');

检查 neo4j github https://github.com/jadell/neo4jphp/wiki/Indexes中的示例

于 2014-07-09T11:23:08.200 回答
1

您可以在浏览器中查看索引:schema

不确定您的产品索引?我不熟悉 Neo4jPHP API。你确定它是一个新的样式模式索引吗?

您也可以使用普通密码语句创建索引或约束。

create index on :Product(product_id)

或者

create constraint on (p:Product) assert p.product_id is unique

请参阅:http ://docs.neo4j.org/chunked/milestone/query-schema-index.html

于 2014-07-09T10:44:19.560 回答