Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-16-2021 06:29 AM
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 thatTEXT
indexes are only used when it is known that the predicate evaluates tonull
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
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
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?
All the sessions of the conference are now available online