# 如何在插件中在评论页面主题上使用 topic\_query.rb 中的 apply\_custom\_query

**URL:** <https://meta.discourse.org/t/how-to-use-apply-custom-query-from-topic-query-rb-on-review-page-topics-in-plugin/131590>\
**Category:** Development\
**Created:** [2019年十月21日 21:23 UTC](https://meta.discourse.org/t/how-to-use-apply-custom-query-from-topic-query-rb-on-review-page-topics-in-plugin/131590 "2019-10-21T21:23:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver\_Walker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/oliver_walker/32/155432_2.png) [@Oliver\_Walker](https://meta.discourse.org/u/Oliver_Walker)\
**Post date:** [2019年十月21日 21:23 UTC](https://meta.discourse.org/t/how-to-use-apply-custom-query-from-topic-query-rb-on-review-page-topics-in-plugin/131590/1 "2019-10-21T21:23:23Z")

</div>

你好，

我有一个插件，它使用了 TopicQuery.add\_custom\_filter 函数。

它按预期仅将我的自定义过滤器应用于着陆页上显示的默认主题视图。

我注意到这是因为在 topic\_query.rb 文件的 default\_results 方法中，调用 apply\_ordering 来应用我的自定义过滤器：

```
    result = apply_ordering(result, options)

```

这很好，但并不是我想要的。我希望该过滤器能应用于 /review 页面下显示的任何内容。我不确定该如何实现。

有人熟悉代码的这一部分吗？

我目前进行过滤的方式可以在这里看到：  
[https://github.com/hms-networks/discourse-location-filters/blob/test/app/controllers/filter\_controller.rb](https://github.com/hms-networks/discourse-location-filters/blob/test/app/controllers/filter_controller.rb)

我提到的 Discourse Ruby 文件是这个：

> <https://github.com/discourse/discourse/blob/main/lib/topic_query.rb>

---

<div class="post-metadata">

**Author:** ![Oliver\_Walker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/oliver_walker/32/155432_2.png) [@Oliver\_Walker](https://meta.discourse.org/u/Oliver_Walker)\
**Post date:** [2019年十月22日 15:58 UTC](https://meta.discourse.org/t/how-to-use-apply-custom-query-from-topic-query-rb-on-review-page-topics-in-plugin/131590/2 "2019-10-22T15:58:51Z")

</div>

我想我在开始探索这个主题查询路径时搞砸了，因为看起来 reviewables 甚至没有使用那些主题查询函数，所以我无法通过这种方式应用自定义过滤器。

另外，我对 apply\_custom\_filters 的参数仍然有些困惑。results 是指主题的 Ruby 哈希吗？topic\_query 是否只是该类的一个实例？

接下来，我不确定这是否是正确的做法，但我会尝试找出如何覆盖 reviewables\_controller#index 函数，以便根据当前用户从 reviewables 列表中移除某些主题。

如果您能提供一些建议和指导就太好了 🙂
