我在ROR中使用sunspot-solr,我需要帮助来创建使用两个表的可搜索块.(两个表的连接) 形成索引时我要执行的查询是:
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仅当两个表中都存在ID并且两个ID都具有状态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当我搜索一个单词时,我得到了5条结果.
When I searched a word, I got 5 results.
但是当我从table_two中删除其中一个结果的条目并再次搜索相同的单词时..当我只应该获得另外4个结果时,我仍然有5个结果.
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.
有帮助吗?
推荐答案因此,为了解决该问题,我在控制器中做了类似without(:id,nil)的操作,并且得到了所需的结果.
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.
更多推荐
在Sunspot Solr + Rails 4中使用两个表进行索引
发布评论