# Escaping the "#" character in search

**URL:** https://meta.discourse.org/t/escaping-the-character-in-search/67249
**Category:** Bug
**Created:** [8월 1, 2017, 2:10오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249 "2017-08-01T14:10:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [8월 1, 2017, 2:10오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/1 "2017-08-01T14:10:12Z")

</div>

Is there an escape character for search?

One of our users was trying to search for “pozidrive #4” and it returned no hits, searching for “Pozidrive” works, but he was looking specifically for #4.

---

<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: [8월 1, 2017, 2:20오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/2 "2017-08-01T14:20:28Z")

</div>

You just hit 3 bugs-in-one … you get the 🎃 ♨

Your actual bug:

`#4` is treated as a category filter and by adding it search is assuming you are trying to find all topics in the category id 4, or something along those lines. `#` should not allow for category id, and always just pass through misses.

Two side bugs I discovered while answering this:

- Our prettifier is mucking big time with search results. “pozidrive” as a search term returns zero results, most likely cause of the quotes. I have to fix that.

- Our # autocomplete is all messed up in composer, #2space and the autocomplete is still open. It should always unconditionally close on space.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [8월 1, 2017, 2:37오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/4 "2017-08-01T14:37:09Z")

</div>

> [@sam](#):
>
> Our prettifier is mucking big time with search results. “pozidrive” as a search term returns zero results, most likely cause of the quotes. I have to fix that.

Quoted search strings work on our instance:

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/2/9274bbeff14270abcec431255191ea6ab9ddcedd.png)

---

<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: [8월 1, 2017, 2:41오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/5 "2017-08-01T14:41:28Z")

</div>

This is not about that, it is about “americandream” \<= try searching for that sans quotes

---

<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: [8월 1, 2017, 9:35오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/6 "2017-08-01T21:35:33Z")

</div>

@tgxworld I would like you to take the “cannotfindthis” problem. This is actually only a problem for our hosting.

Our default PG install returns:

```plaintext
local and image

[1] pry(main)> Post.exec_sql("select to_tsvector('english', '“test”')").to_a
=> [{"to_tsvector"=>"'test':1"}]

Our production pg

[1] pry(main)> Post.exec_sql("select to_tsvector('english', '“test”')").to_a
=> [{"to_tsvector"=>"“test”':1"}]

```

And:

```plaintext
Local + Dev + Image

pry(main)> Post.exec_sql("select ts_debug('english', '“test”')").to_a
=> [{"ts_debug"=>"(blank,\"Space symbols\",“,{},,)"},
 {"ts_debug"=>"(asciiword,\"Word, all ASCII\",test,{english_stem},english_stem,{test})"},
 {"ts_debug"=>"(blank,\"Space symbols\",”,{},,)"}]

PRD

pry(main)> Post.exec_sql("select ts_debug('english', '“test”')").to_a
[{"ts_debug"=>"(word,\"Word, all letters\",“test”,{english_stem},english_stem,{“test”})"}]

```

So there is something about our PG install in our PRD containers that is missing “smart quotes” from the space chars. This is going to cause some severe problems in search quality so we need it fixed asap.

---

<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: [8월 1, 2017, 10:20오후 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/8 "2017-08-01T22:20:46Z")

</div>

The OP is fixed per

[https://github.com/discourse/discourse/commit/97fa64d8468ab91265c9a8b1b9f42e62c40ca8de](https://github.com/discourse/discourse/commit/97fa64d8468ab91265c9a8b1b9f42e62c40ca8de)

Keep in mind # in search is used as a special delimiter to search for tags and categories, I added a bypass here if there are zero matching categories and tags. However, if you do a search for say #docker on meta, it will not find this post cause docker is a legit tag name.

There is an open question to @codinghorror on weather we should allow unqualified `#TAG` as opposed to requiring qualification for tags like the auto complete adds (eg: for tag search require `#docker::tag` and always pass through `#docker` )

I am mixed on changing this cause the bypass should be good enough ™

Leaving open so @tgxworld can sort out the extreme problem of “test” in our infrastructure and look at autocomplete which is weird.

@tgxworld feel free to split this up and close if you wish.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [8월 3, 2017, 2:03오전 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/9 "2017-08-03T02:03:09Z")

</div>

Closing this as I’m bringing the discussion into our internal forum.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [8월 3, 2017, 2:03오전 UTC](https://meta.discourse.org/t/escaping-the-character-in-search/67249/10 "2017-08-03T02:03:14Z")

</div>


