0
votes

I wonder how can i build a Cypher query that will combine Fulltext and Simple indexes using spring data neo4j. Consider the following node entity:

@NodeEntity
public class SomeObject {

    public SomeObject() {

    }

    public SomeObject(String name, int height) {
        this.name = name;
        this.height = height;
    }

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "search_name")
    String name;

    @Indexed(numeric = false)
    int height;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

OK, so my question is how can i run a query (By using a SomeObject Graph Repository) that will start from SomeObject nodes, by referencing their simple indexes and full-text indexes in the same query. For example i would like to write something like that:

START n=node:SomeObject('name: Roy AND height: [170 TO 190]') RETURN n

I know that i cannot write it exactly like that, because spring data neo4j forces me to give a seperate index name for fields that are needed to be FULLTEXT indexed. But what if i need make an index lookup for my SomeObject entity which combines both fileds? (name & height)

What are the best practices in such case? Is there a way to combine them both in the same query? or maybe should i query each of them separably, and then to perform some some kind of intersection between the two results, so i will get exactly the nodes the meet my original query lookup condition? (name: Roy AND height: [170 TO 190]).

Thanks! Roy.

1

1 Answers

1
votes

I'd never launch two separate queries. Maybe just use one index as a starting point in your query?

START n=node:search_name('name: Roy')
WHERE n.height >= 170 AND n.height <= 190
RETURN n

How's the performance of this query? This bypasses the SomeObject index, but I don't see any other option as you indeed cannot combine both indexes.

I as also thinking about the following query, but you'd still end up with duplicates:

START n=node:search_name('name: Roy'), m=node:SomeObject('height: [170 TO 190]')
RETURN DISTINCT n,m