New 4.4 Text Index with non static string?

bleimehl
Node

Hi there,

does any anybody know a workaround to use the new Text Indexes with a non static string.

The documentation says:

TEXT indexes only work for predicates operating on strings. That means that TEXT indexes are only used when it is known that the predicate evaluates to null for all non-string values.

source: The use of indexes - Neo4j Cypher Manual

Lets have an example:

CREATE (n:TestTextNode{text:"loren ipsum blabla"});
CREATE (m:TestSearchStringNode{str:"bla"});
CREATE TEXT INDEX FOR (i:TestTextNode) ON (i.text);

If we now do a query with a static string we see the index beeing used:

EXPLAIN MATCH (n:TestTextNode) WHERE n.text CONTAINS "bla" return n.text

3X_9_4_941731c5f0288eacd1feb4dcb664c82dcb16d3c2.png

But if we want to match non static we get a full scan

EXPLAIN 
MATCH (w:TestSearchStringNode)
WITH w
MATCH (n:TestSearchStringNode) WHERE n.text CONTAINS w.str return n.text

3X_4_2_42a81ae87268b95d0f5ce61c3bec26a2e587cc08.png

If we take the documentation literally

indexes are only used when it is known that the predicate evaluates to null for all non-string values

toString should match these criterias. It always returns a string or null (or an raises an error)

But lets see what we get

EXPLAIN 
MATCH (w:TestSearchStringNode)
WITH w
MATCH (n:TestSearchStringNode) WHERE n.text CONTAINS toString(w.str) return n.text

Sorry, new users can only put 2 embedded media items in a post.

oh cmon. Ok you have to believe me; here should be a screenshot of a explain plan telling you the query wont use any indexes

Ouch, the index wont be used again.

or even simpler

EXPLAIN 
WITH "bla" as w
MATCH (n:TestSearchStringNode) WHERE n.text CONTAINS toString(w) return n.text

Sorry, new users can only put 2 embedded media items in a post.

oh cmon. Ok you have to believe me; here should be a screenshot of a explain plan telling you the query wont use any indexes

This makes the use cases of the new text indexes very narrow for us.

Does anybody know a workaround or are there any plans to make TEXT indexes more flexibel?

0 REPLIES 0