Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 太阳黑子搜索属于联想_Ruby On Rails_Ruby On Rails 3_Solr_Full Text Search_Sunspot - Fatal编程技术网

Ruby on rails 太阳黑子搜索属于联想

Ruby on rails 太阳黑子搜索属于联想,ruby-on-rails,ruby-on-rails-3,solr,full-text-search,sunspot,Ruby On Rails,Ruby On Rails 3,Solr,Full Text Search,Sunspot,我有一个属于多个其他表的结构模型 class Fabric < ActiveRecord::Base validates :name, presence: true belongs_to :design belongs_to :composition belongs_to :collection belongs_to :style belongs_to :origin belongs_to :texture belongs_to :supplier ha

我有一个属于多个其他表的结构模型

class Fabric < ActiveRecord::Base
  validates :name, presence: true
  belongs_to :design
  belongs_to :composition
  belongs_to :collection
  belongs_to :style
  belongs_to :origin
  belongs_to :texture
  belongs_to :supplier
  has_and_belongs_to_many :colours

  searchable do
    text :name, :boost => 5 
    text :description
    text :composition do
      composition.name
   end
    text :collection do
      collection.name
    end
   text :style do
     style.name
   end
   text :origin do
     origin.name
   end
   text :texture do
     texture.name
  end
   text :supplier do
      supplier.name
  end
  end
  end

Ross

看起来您在模型更新后没有重新编制数据索引

运行此命令以重新索引:

bundle exec rake sunspot:solr:reindex

您需要在全文中传递block,以指定要搜索的字段

@search = Fabric.search do
  fulltext params[:search] do
    fields(:collection, :style, :origin)
  end
  .....
end
以下是如何在可搜索块中建立索引。索尔从文件的角度思考。它不在乎是否有关联

searchable do 
  text :collection do 
    collection.text 
  end
end
然后重新编制索引

查看此项了解更多详细信息


如果某些关联可能为零,请不要忘记进行测试,否则在重建索引时会出现错误

text :collection do 
  collection.name if collection
end

你能显示你的搜索栏吗?您也需要重新编制索引。这就是您要查找的内容吗,非常感谢。如果每个相关联的表:collection、:style等都有一个文本列:name,那么此方法是否针对这些列进行搜索?
text :collection do 
  collection.name if collection
end