【问题标题】:removing duplicates from Sphinx Search based on 1 column根据 1 列从 Sphinx 搜索中删除重复项
【发布时间】:2015-08-17 21:04:23
【问题描述】:

我有一个需要搜索的表,该表是通过其他 2 个表之间的join 形成的。 ThinkingSphinx::Index 是在表 posts 上定义的,我的 posts_index.rb 看起来像这样:

join 'LEFT JOIN threads on posts.id = threads.id'
indexes 'posts.text', as: posts_text
indexes 'threads.text', as: threads_text

还有我的桌子:

threads
| id | text       |
| 0  | test title |
| 1  | foo  bar   |

posts
| id | parent | text
| 0  | 0      | some stuff
| 1  | 0      | more stuff

我需要做的是对thread.textposts.text 执行狮身人面像搜索。假设我搜索了stuff这个词,这又回来了

thread.id | posts.id | thread.text | posts.text |
0         | 0        | test title  | some stuff |
0         | 1        | test title  | more stuff |

这是我需要的,但如果我搜索单词 test,就会返回

thread.id | posts.id | thread.text | posts.text |
0         | 0        | test title  | some stuff |
0         | 1        | test title  | more stuff |

这不是我想要的,你可以看到返回了一个额外的不必要的行,在这种情况下我只想要第一行。我不能做group_by,因为一个线程可以有许多可能/可能不包含搜索词的帖子,我仍然需要返回所有被点击的posts。唯一不想要某个重复结果的情况是,如果搜索词仅在主题标题中找到。由于各种原因,我不能只在 sphinx 搜索之后编写一个过滤器,它必须写入查询中。

【问题讨论】:

    标签: sphinx thinking-sphinx


    【解决方案1】:

    这样做的唯一方法是安排 thread.text 列在除一个帖子(例如第一个)之外的所有帖子上都是空白的,这样与主题标题匹配的关键字只能与一个帖子匹配。

    (但是你不能得到匹配,有些词匹配标题,有些匹配文章文本,除了第一篇文章)

    ... 也不确定如何在 ThinkingSphinx 中进行安排。

    【讨论】:

      【解决方案2】:

      不是一个真正的解决方案,但我最终只是添加了另一个索引并从另一个索引中删除了标题字段。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-09
        • 1970-01-01
        • 1970-01-01
        • 2017-03-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多