Indexing using two tables in sunspot solr + rails 4

亡梦爱人 提交于 2019-12-25 07:54:43

问题


I'm using sunspot-solr in ROR and I need help in creating a searchable block using two tables.(join of two tables) The query I want to be executed when the indexes are formed is :

SELECT a.id,a.title
FROM table_one a,table_two b 
WHERE a.status=1 
AND a.id=b.id 
AND b.status=1  

I want the "title" field to be searchable(text), only if the id exists in both tables and both have status 1.And I want them to be stored fields(no db hits).

class TableOne
  has_many :table_twos
 searchable do
  text :title, :stored => true
  string :status, :stored => true
  string :id, :multiple => true, :stored => true do
         table_twos.map(&:id)
 end
end

When I searched a word, I got 5 results.

But when I delete an entry of one of the results from table_two and searched the same word again.. I still got 5 results when I should get only the other 4.

Any help ?


回答1:


If you delete an associated record that was stored as a solr/sunspot record, you will have no choice but to reindex that record.




回答2:


So to solve the issue I did somthing like without(:id,nil) in my controller and I got the results as I wanted them.

I'm not sure its the right way to go about it though.



来源:https://stackoverflow.com/questions/31512210/indexing-using-two-tables-in-sunspot-solr-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!