【问题标题】:How to join a model in solr with rails sunspot如何在 solr 中加入带有 rails sunspot 的模型
【发布时间】:2014-12-17 17:56:58
【问题描述】:

我需要加入另一个模型(GeoNameAlternateName)并根据文档进行尝试。但由于某种原因,我收到以下错误:

ArgumentError: Unknown field option :prefix provided for field :name

我的 GeoNameCityModel 可以这样搜索:

searchable do
text :name
string :feature_class
string :feature_code
latlon(:lonlat) { Sunspot::Util::Coordinates.new(lat, lon) }
join(:name, :prefix => "alternate", :target => GeoNameAlternateName, :type => :text, :join => { :from => :geonames_id, :to => :geonames_id })
end

两个模型都有字段列?这可能会干扰吗?

我在 mac osx,rails 4.1.8 上运行, ruby-2.1.1/gems/sunspot_solr-2.1.1/solr solr 规范 4.2.0.2013.03.06.22.32.13 solr-impl 4.2.0 1453694 - rmuir - 2013-03-06 22:32:13 lucene 规范 4.2.0 lucene-impl 4.2.0 1453694 - rmuir - 2013-03-06 22:25:29

【问题讨论】:

    标签: ruby-on-rails solr sunspot


    【解决方案1】:

    “前缀”不在太阳黑子2.1.1 中,是后来添加的。想用的话就切换到master分支

    在你的情况下,它应该是这样的:

    Sunspot.setup(GeoNameAlternateName) do
     integer :id
     ... all other fields 
    end
    
    Sunspot.setup(GeoNameCityModel) do
     integer :id
     integer :geoname_id
     join(:name, :type => :text, :join_string => 'from=geoname_id to=id')
     ... all other fields 
    end
    

    【讨论】:

    • 但是这里的 GeoNameAlternateName 表是如何引用的呢?
    • 而且它不起作用,它不考虑来自 GeoNameAlternateName 表的任何结果
    • Solr 不是关系数据库。在 Solr 中,GeoNameAlternateName 和 GeoNameCityModel 都将在同一个集合中结束。因此,您必须将“外键”添加到 GeoNameCityModel。你的两个模型都应该有 id 字段。 [这里](GeoNameCityModel) 是太阳黑子源代码中的一个示例,here 是 Solr 连接文档。
    • 抱歉,不知道如何编辑评论。这是上一条评论中缺少的link
    • 不,它根本不起作用。如链接所示,我尝试设置过于简单的模型,但我没有得到匹配
    【解决方案2】:

    我让它运行起来了。 首先,我必须使用 git repo 中的最新版本

      gem 'sunspot_rails'  , :git => 'https://github.com/sunspot/sunspot.git'
      gem 'sunspot_solr', :git => 'https://github.com/sunspot/sunspot.git' # optional pre-packaged Solr distribution for use in development
    

    然后在模型中:

    join(:alternate_name,  :target => GeoNameAlternateName, :type => :text, :join => { :from => :geonames_id, :to => :geonames_id })
    

    在连接模型 GeoNameAlternateName 中

     searchable do
        integer :geonames_id
        text :alternate_name
      end
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 2023-03-15
    相关资源
    最近更新 更多