【问题标题】:Issue Performing FullText Search on Entity对实体执行全文搜索的问题
【发布时间】:2012-06-13 18:29:13
【问题描述】:

我正在使用 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 指南的 Fulltext Search 部分,但我看不出我缺少什么来完成这项工作。我的理解是 :name 属性应该被索引,因为我配置模型的方式。

【问题讨论】:

    标签: ruby-on-rails ruby neo4j


    【解决方案1】:

    您使用的是哪个版本的 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 索引并查询两个字段:nametype

    【讨论】:

    • bundle show 输出以下内容:neo4j (2.0.1)、neo4j-community (1.7.1)、neo4j-core (2.0.1)、neo4j-wrapper (2.0.1)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 2021-10-24
    相关资源
    最近更新 更多