LDB
LDB

Reputation: 692

Neo4j.rb - NameError: undefined local variable or method when using where

I am trying to retrieve all BISAC nodes having the word "Art" in the description.

ba = Bisac.where(bisac_value =~ '.*Art.*')
NameError: undefined local variable or method `bisac_value' for main:Object

The equivalent cypher query retrieves 10 nodes.

MATCH (b:Bisac) WHERE (b.bisac_value =~ '.*Art .*') RETURN b;

What I am doing wrong here?

Upvotes: 1

Views: 77

Answers (3)

LDB
LDB

Reputation: 692

Removed Kaminari from pagination and used will_paginate. Used page_entries_info

Problem solved.

Upvotes: 0

Brian Underwood
Brian Underwood

Reputation: 10856

Your solution will certainly work, but an easier one which doesn't resort to using the Query API is to simply use a Ruby regular expression:

Bisac.all(:l).where(bisac_value: /.*Art.*/)

You can even use a case-insensitive regular expression (/.*Art.*/i) which will get translated into Cypher syntax as well.

Upvotes: 1

LDB
LDB

Reputation: 692

Found the answer (in the documentation), here is the link: http://neo4jrb.readthedocs.org/en/5.1.x/Querying.html

The query should be:

ba = Bisac.all(:l).where("l.bisac_value =~ {the_value}").params(the_value: '.*Art.*').pluck(:l)

or, much simpler:

ba = Bisac.all(:l).where("l.bisac_value =~ '.*Art.*'").pluck(:l)

Upvotes: 0

Related Questions