在Sunspot Solr + Rails 4中使用两个表进行索引 [英] Indexing using two tables in sunspot solr + rails 4

查看:91
本文介绍了在Sunspot Solr + Rails 4中使用两个表进行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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中使用两个表进行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆