我正在使用neo4j作为Ruby on Rails项目的后端,我正在尝试实现一些搜索功能。波纹管是我的模型:
class Entity < Neo4j::Rails::Model
property :name
has_n(:friends).to(Entity)
index :name, :type => :fulltext
end
我创建了以下内容的记录:
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
最后,我的搜索方法如下所示:
def search
terms = params[:q]
render :json => Entity.all(:name => terms, :type => :fulltext)
end
当我运行上述搜索方法时,出现以下错误:no index on field type
我已经阅读了Neo4j-Rails指南的全文搜索部分,但我没有看到我缺少什么来完成这项工作。我的理解是,由于我配置模型的方式,应该对 :name 属性进行索引。
你使用的是哪个版本的neo4j.rb?如果你使用的是2.0,你应该看看Neo4j Github Wiki页面。
下面是如何使用 2.0 解决此问题的示例:
Entity.all("name: hello*", :type => :fulltext).count
我想这也适用于 Neo4j.rb 1.3.1。哈希查询不适用于全文搜索。
以下查询:
Entity.all(:name => "hello*", :type => :fulltext).count
将使用确切的 Lucene 索引并查询两个字段:name
和 type
。