cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to filter results from Full-Text indexes?

Hello everybody!

I am new in the forums and more or less new to Neo4j. I have been working with it just a year. I am working with Neo4j 4.3.3.
I have a DB with a Full-Text Index and is working fine. But I would like to filter the results from the CALL to the index. I have done a little query as follows:

CALL db.index.fulltext.queryNodes("index_name","searchTerm~")  
YIELD node, score 
MATCH p=(m:Movie)--(a:Actor) WHERE id(a)=id(node) 
return a.content,score
ORDER BY score DESC

It works. But...I think is not that good in performance, or maybe that it could improve.
The question is if I can create a subset of nodes where to apply the index, and not like I did, which is the other way around? Any idea How could I improve the filter?. I just show one relationship I have to do, from some others, so the final query could be heavy on that last part.

Thanks in advance!

1 ACCEPTED SOLUTION

I'm not entirely sure of all that you're asking, but once you have the node variable from the index call, you don't need to re-match to it (for your a node), you can use a WITH clause followed by a WHERE (although you can alias the result of the CALL), such as:

CALL db.index.fulltext.queryNodes("index_name","searchTerm~")  YIELD node, score 
WITH node as a, score
WHERE a:Actor AND (a)--(:Movie)
RETURN a.content, score
ORDER BY score DESC

The WITH ... WHERE covers your filtering of the node needing to be an :Actor labeled node and must have any relationship to any :Movie node.

View solution in original post

2 REPLIES 2

I'm not entirely sure of all that you're asking, but once you have the node variable from the index call, you don't need to re-match to it (for your a node), you can use a WITH clause followed by a WHERE (although you can alias the result of the CALL), such as:

CALL db.index.fulltext.queryNodes("index_name","searchTerm~")  YIELD node, score 
WITH node as a, score
WHERE a:Actor AND (a)--(:Movie)
RETURN a.content, score
ORDER BY score DESC

The WITH ... WHERE covers your filtering of the node needing to be an :Actor labeled node and must have any relationship to any :Movie node.

Hi, @andrew.bowman thanks for the response. I think your approach makes more sense than mine. And I have already tested the query and I think works faster than mine. I also use the EXPLAIN command and it seems that this approach is better, but I am still learning to interpret the explanations. Also, I did not know that you could use the "a:Actor" in the WEHRE part.

Thank you so much!