# 多标签搜索支持 AND 和 OR 吗？

**URL:** <https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041>\
**Category:** Feature\
**Tags:** completed\
**Created:** [2017年一月19日 20:02 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041 "2017-01-19T20:02:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)\
**Post date:** [2017年一月19日 20:02 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/1 "2017-01-19T20:02:04Z")

</div>

我认为在搜索多个标签时出现了一个错误。以下是我在我的 Discourse 上得到的奇怪结果：

img src=“[//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/9/d/9d9e5d0ba84892a132ca1505ed87d1e7deb222b4.png](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/9/d/9d9e5d0ba84892a132ca1505ed87d1e7deb222b4.png)” width=“690” height="428"

根据搜索结果，应该有 8 条结果。但实际上显示了 9 条。第二个结果是正确的，但第一个结果却不正确。

我怀疑这个问题与连字符有关，因为错误的结果中也包含一个包含部分搜索词的 a 标签（`-reports`）。当只搜索 `committee-reports` 时，这个问题并没有出现。

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [2017年一月19日 20:10 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/2 "2017-01-19T20:10:56Z")

</div>

I might be reading this wrong, but wouldn’t this simply imply the topic only needs to contain one of the provided tags?

> <https://github.com/discourse/discourse/blob/0a78ae739d0b14b6bfc2654c51be5907c28d3f8f/lib/search.rb#L393-L402>

Or am I reading that incorrectly?

---

<div class="post-metadata">

**Author:** ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)\
**Post date:** [2017年一月19日 20:18 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/3 "2017-01-19T20:18:21Z")

</div>

![](https://global.discourse-cdn.com/meta/original/3X/e/7/e7fc376a4c46a09562b46240d14b89deeb9a61be.gif)

I guess it’s late 😊

Thanks for pointing out what should have been obvious.

Is there a way to search for two tags with AND instead of OR?

---

<div class="post-metadata">

**Author:** ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)\
**Post date:** [2017年一月20日 13:17 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/4 "2017-01-20T13:17:31Z")

</div>

鉴于这个话题被移到了 #Contribute > Feature 分类，我猜这是暂时不行吧 🙂

---

<div class="post-metadata">

**Author:** ![burke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/burke/32/4211_2.png) [@burke](https://meta.discourse.org/u/burke)\
**Post date:** [2017年二月17日 22:49 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/5 "2017-02-17T22:49:30Z")

</div>

FWIW, I was just doing a multiple tag search to share a list of posts with someone and expected the search would return the intersection (AND) instead of the union (OR). So, found this post and adding a +1 👍 for the option to AND multiple tags in a search.

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [2017年二月18日 00:43 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/6 "2017-02-18T00:43:39Z")

</div>

@burke, you can actually do it but it isn’t performant (depending on the number of tags and topics you have)  
[Multiple Tags search query takes too long ? - big forum - #3](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/3)

You would specify the tag item multiple times, such as `tag:pr-welcome tag:foobar`

---

<div class="post-metadata">

**Author:** ![medha](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@medha](https://meta.discourse.org/u/medha)\
**Post date:** [2017年二月19日 21:13 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/7 "2017-02-19T21:13:14Z")

</div>

Hi,  
Outreachy aspirant here 🙂 I have successfully installed and run Discourse locally on my machine based on the instructions provided in the Beginners’ development guidelines. I am going through the codebase currently and was trying to get started on a beginner level issue. Is this a good place to start?  
Thanks.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年二月19日 23:30 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/8 "2017-02-19T23:30:22Z")

</div>

> [@medha](#):
>
> Is this a good place to start?

I am afraid this is a bit involved, I would pick something a bit more straight forward. PM me with a list of 5 or so features/bugs you find interesting and I will help guide you to the best place to start.

---

<div class="post-metadata">

**Author:** ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)\
**Post date:** [2017年二月20日 08:51 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/9 "2017-02-20T08:51:28Z")

</div>

Thanks for pointing out to this helpful workaround @cpradio!

---

<div class="post-metadata">

**Author:** ![medha](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@medha](https://meta.discourse.org/u/medha)\
**Post date:** [2017年二月22日 02:44 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/10 "2017-02-22T02:44:13Z")

</div>

Thanks for the guidance, I am now looking for issues that I am able to understand/find interesting.  
Also, there is a lock icon many of the issues. Does that imply they are not open to all contributors?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年二月22日 12:50 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/11 "2017-02-22T12:50:40Z")

</div>

Closed topics are topics we are done with, they are completed.

---

<div class="post-metadata">

**Author:** ![dmacjam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmacjam/32/67659_2.png) [@dmacjam](https://meta.discourse.org/u/dmacjam)\
**Post date:** [2017年六月2日 11:05 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/12 "2017-06-02T11:05:56Z")

</div>

[https://github.com/discourse/discourse/pull/4896](https://github.com/discourse/discourse/pull/4896)

With this pull request now it is possible to do logical AND search by multiple tags and the performance is the same for any number of tags. Example search: `tag:pr-welcome+foobar`

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2025年五月15日 00:31 UTC](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041/13 "2025-05-15T00:31:18Z")

</div>


