Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing of Properties with array values #76

Open
arpitjoshi opened this issue Apr 4, 2013 · 5 comments
Open

Indexing of Properties with array values #76

arpitjoshi opened this issue Apr 4, 2013 · 5 comments

Comments

@arpitjoshi
Copy link

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.

@philippemiguet
Copy link

@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?

@jadell
Copy link
Owner

jadell commented Apr 30, 2014

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.

@philippemiguet
Copy link

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
Copy link

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 :)

@JugalSA
Copy link

JugalSA commented May 31, 2016

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]..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants