在Sunspot Solr + Rails 4中使用两个表进行索引

编程入门 行业动态 更新时间:2024-10-25 22:25:02
本文介绍了在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中使用两个表进行索引

本文发布于:2023-10-30 12:06:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   两个   Sunspot   Solr   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!