Issue Performing FullText Search on Entity
I'm using neo4j as my backend to a Ruby on Rails project and I'm attempting to implement some search functionality. Bellow is my model:
class Entity < Neo4j::Rails::Model property :name has_n(:friends).to(Entity) index :name, :type => :fulltext end
I have created records with the following:
Neo4j::Transaction.run do Entity.destroy_all tony = Entity.new :name => "Tony Soprano" paulie = Entity.new :name => "Paulie Gualtieri" robert = Entity.new :name => "Robert Baccalier" silvio = Entity.new :name => "Silvio Dante" tony.friends << paulie << robert << silvio tony.save end
Lastly my search method looks like this:
def search terms = params[:q] render :json => Entity.all(:name => terms, :type => :fulltext) end
When I run the above search method, I'm getting the following error: no index on field type
I've read the Fulltext Search section of the Neo4j-Rails Guides and I don't see what I'm missing to make this work. My understanding is the :name property should be indexed because of the way I configured the model.
Which version of neo4j.rb are you using ? If you are using 2.0 you should look at the Neo4j Github Wiki Pages.
Here is an example how to solve that using 2.0:
Entity.all("name: hello*", :type => :fulltext).count
I guess this also works in Neo4j.rb 1.3.1. Hash queries does not work with fulltext search.
The following query:
Entity.all(:name => "hello*", :type => :fulltext).count
will use the exact lucene index and query two fields: name and type.