neo4jphp icon indicating copy to clipboard operation
neo4jphp copied to clipboard

Indexing of Properties with array values

Open arpitjoshi opened this issue 11 years ago • 5 comments

I am creating node with one of the property with array values and trying to index that property. Trying to search nodes using index for some value, but gives zero result.

Attaching the screenshot of my PHP code. Screen Shot 2013-04-04 at 8 10 43 PM

Now Cypher Query: START root=node:tags_index(tags='Yoga') RETURN root.name, root.id, root.tags Returns zero result.

The string array values of tags are not indexed separately.

looking at this url http://grokbase.com/t/gg/neo4j..., It says array values are saved as individual values to the same key.

But this is not happening using PHP Everyman client, is there some issue with Everyman library.

arpitjoshi avatar Apr 04 '13 14:04 arpitjoshi

@arpitjoshi If I'm right, you have totell neo4j to index each value of the array separatly. Then it should work :) I've tested on my install with an array property and it works well.

@jadell What about handling mixed $value on add( \Everyman\Neo4j\PropertyContainer $entity, string $key, string $value ) : boolean instean of string in the classes reposible of the indexes?

philippemiguet avatar Apr 30 '14 12:04 philippemiguet

That should just work. Only the method docblocks say it should be a string -- that is already incorrect since it could be an int, float, or boolean. Technically, it can be any scalar value or a 0-indexed array of all the same type.

jadell avatar Apr 30 '14 13:04 jadell

Ok it's just because I've got a php notice. Also I'm pretty sure the query doesn't return anything if I don't specifically add each value of the array in the index.

I'm off the office until next week. On Monday, I'll give it another try just to be sure and post the notice here.

philippemiguet avatar May 01 '14 11:05 philippemiguet

Hi @jadell,

Here is the notice when I try to index a property which is an array of strings:

PHP Notice:  Array to string conversion in /opt/testproject/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Batch/AddTo.php on line 95

//Line 95
public function matchId()
{
       return parent::matchId() . spl_object_hash($this->index) . $this->key . $this->value;
}

About the query, I have a node with a property generic_keys which is an array: array("bwm", "ford")

If I add the property as it in the index (i.e, the whole array of strings), the following query returns 0 row

START root=node:Company(generic_keys="bmw")
RETURN root

If I add each value of the array in the index, the query returns 1 row. Which is what I expect here, and seems to be how neo4j handle array properties.

Can you tell me if I'm wrong and how I can make it work?

Cheers :)

philippemiguet avatar May 06 '14 09:05 philippemiguet

So how to write this in php..?? In for loop latest value will override the last value..

If I do this..

$arr = array(123, 456, 789);

foreach($arr as $key){ $second_node->setProperty('tags', $key)->save(); $storyIndex->add($second_node, 'tags', $second_node->getProperty('tags')); }

In this case final value of tags will be 789..But it should be [123,456,789]..

JugalSA avatar May 31 '16 09:05 JugalSA