我使用neo4j作为Ruby on Rails项目的后端,并尝试实现一些搜索功能。Bellow是我的模型:
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指南的Fulltext Search部分,我不认为我遗漏了什么来让它工作。我的理解是:name属性应该被索引,因为我配置模型的方式。
发布于 2012-06-14 15:01:20
您使用的是哪个版本的neo4j.rb?如果你使用的是2.0,你应该看看Neo4j Github Wiki Pages。
下面是一个使用2.0解决该问题的示例:
Entity.all("name: hello*", :type => :fulltext).count我猜这也适用于Neo4j.rb 1.3.1。哈希查询不适用于全文搜索。
以下查询:
Entity.all(:name => "hello*", :type => :fulltext).count将使用精确的lucene索引并查询两个字段:name和type。
https://stackoverflow.com/questions/11021104
复制相似问题