Multi-valued field indexing


(Dbeaumon) #1

Is it possible to apply an index to a list of (string) values, so that you can efficiently look up "all nodes with a list property that contains X".

I have tried creating the index, and adding a list of strings, but any cypher search I do either returns nothing, or the profile shows the results are obtained via a label scan and not the index.

If it is possible:
a) Does the CREATE INDEX statement need to do anything special?
b) What does the MATCH statement look like?

Thanks,

Dave


(Andrew Bowman) #2

Currently this kind of lookup isn't supported with schema indexes. We would advise remodeling these as connected nodes to your main node.

For example, if you had something like:

(:Sentence {id:12345, words:['sphynx', 'of', 'black', 'quartz', 'judge', 'my', 'vow']})

We would advise you to remodel such that:

(:Sentence {id:12345})-[:HAS_WORD]->(:Word {word:'sphynx'})

and so forth with a separate :Word node per word, and an index on :Word(word) for quick lookup.

Your :Word nodes would be reused with other :Sentence nodes so you could find similar sentences with the same words:

MATCH (w:Word)<-[:HAS_WORD]-(s:Sentence)
WHERE w.word = 'quartz'
RETURN s

(Michael Hunger) #3

Array indexes only find the full array.
You can use a manual index via APOC for that (which indexes each array entry),
or better the new fulltext index for 3.5.


(Dbeaumon) #4

Thanks. APOC was going to be plan B, but the additional manual index maintenance was a headache I didn't really want for a solution to an edge case that I'm hoping will never happen. I'm going to give 3.5 a try - it's about time I took a look.

I assume that the Neo4JRule TestRule code (Java) for 3.5 supports this new indexing for my testing entertainment?


(Michael Hunger) #5

The new indexes are managed via procedures, so i don't see why not.