Search code examples
ruby-on-railssolrsunspot

How to join a model in solr with rails sunspot


I need to join another model (GeoNameAlternateName) and tried it according to the doc. But for some reason I get the following error:

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

My GeoNameCityModel is searchable like this:

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

Both models have a field column? Does this maybe interfere?

I am running on mac osx, rails 4.1.8, ruby-2.1.1/gems/sunspot_solr-2.1.1/solr solr-spec 4.2.0.2013.03.06.22.32.13 solr-impl 4.2.0 1453694 - rmuir - 2013-03-06 22:32:13 lucene-spec 4.2.0 lucene-impl 4.2.0 1453694 - rmuir - 2013-03-06 22:25:29


Solution

  • I got it running. First of all I had to use the latest version from the 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
    

    then in the model:

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

    in the join model GeoNameAlternateName

     searchable do
        integer :geonames_id
        text :alternate_name
      end