gerhard
(Gerhard Schlager)
April 15, 2015, 2:47pm
1
I’m often in the situation where I only want to search for topics that have certain words in their title.
So, it would be great if there was a search modifier that allows me to search only within topic titles (something like title:search text).
7 Likes
sam
(Sam Saffron)
April 15, 2015, 10:39pm
2
Keep in mind title matches are always prioritized. One issue I need to fix is that we are using the snowball stemmer which completely sucks compared to say ispell or something smarter, so it does a fair bit of messing with results.
Fine to add an advanced filter, but not sure it is needed cause we already show title matches first.
4 Likes
nukeador
(Nukeador)
November 2, 2017, 6:00pm
3
My user case is that I need to find all topics with “Meeting” to add them a tag, searching on topics content will return me also false positives
1 Like
Yeah I would like to have this. Anyone who is interested we can fund this work cc @cpradio who may have advice.
6 Likes
pmusaraj
(Penar Musaraj)
November 6, 2017, 2:11pm
5
I will take a stab at this, see if I can figure it out.
7 Likes
cpradio
(cpradio)
November 6, 2017, 2:57pm
6
Only advice I have is pay attention to the tokenizer, as I’m fairly certain that is something you’ll be utilizing.
5 Likes
Hey I’d like to work on this. Is that ok @pmusaraj ? I wouldn’t like to overlap with your stuff if you have something in the works.
7 Likes
erlend_sh
(Erlend Sogge Heggen)
January 25, 2018, 11:18am
8
You’re clear to work on this. @pmusaraj is working with us on other stuff.
5 Likes
pmusaraj
(Penar Musaraj)
January 25, 2018, 12:12pm
9
Yes, that would be great (I couldn’t figure this out).
4 Likes
Pull Request adding this:
master ← jorgemanrubia:search-only-in-title
closed 03:47AM - 20 Feb 18 UTC
It adds a new search option `in:title` that will make it search only in titles.
…
It also adds a new checkbox at the top of the advanced search UI:

See:
- https://meta.discourse.org/t/add-in-title-modifier-to-advanced-search/38546?source_topic_id=77463
- https://meta.discourse.org/t/search-only-within-topic-titles/27600?source_topic_id=77463
## Overview of changes
It changes the way posts and topics are indexed to use [PostgreSQL full-text search weights](https://www.postgresql.org/docs/9.1/static/textsearch-controls.html). Then, it uses the weight associated with `title` to filter by title when searching posts.
Before, it was concatenating `title + body + category` and storing the indexed result. Now, it will store the concatenation of weighted indexed parts.
This is my first experience with PostgreSQL full-text search. I think it is the proper way to do it after checking the docs. The weights system is a little bit bizarre with 4 values (A, B, C, D) but seems to work pretty well.
As a side effect, results will take weight into consideration when sorting. So `title` > `body` > `category`. From [12.3.3. Ranking Search Results](https://www.postgresql.org/docs/9.1/static/textsearch-controls.html):
> If no weights are provided, then these defaults are used:
> {0.1, 0.2, 0.4, 1.0}
So for posts, weights will be 1.0 for title `title`, 0.4 for `body` and 0.2 for `category`. I think this is ok, but it's definitely something good to check before merging the PR. I tested this locally with a database with 19k posts from a forum I used to run, and the sorting made sense to me.
I will add some comments in the code to explain the changes next.
## Reindexing required
`in:title` will only work after re-indexing all the posts. Not sure how to do it automatically when shipping this:
- Should it trigger a reindexing job as part of the deploy? Is there support in place for such tasks? I guess we could launch a job from a migration if not
- Should it just increase [the `INDEX_VERSION` ](https://github.com/jorgemanrubia/discourse/blob/258051809096598a7390cfbdbac3191d4cf865e3/lib/search.rb#L4) and rely on the [indexing job](https://github.com/jorgemanrubia/discourse/blob/2c56f8df7c1eba7ff81bc66eaafd1e27a8c4ff19/app/jobs/scheduled/reindex_search.rb#L3) that runs every day?
In development I have used `rake search:reindex` for testing this.
First time with PostgreSQL full text search so it would be great if someone with experience had a look .
10 Likes
sam
(Sam Saffron)
February 20, 2018, 4:39am
11
Per @jorge_manrubia this is now implemented. I pushed the change here:
https://github.com/discourse/discourse/commit/86d12bd44bb23767958364743a2afdf064331c81
Note: the UI is not updated yet, we are going to wait a few betas.
Keep in mind, this change will slowly appear on your forum after the update. We will update the search index for 20k posts every 2 hours to gain the new feature. If you feel like rushing it:
./launcher enter app
rake search:reindex
A rushed reindex is running on meta right now.
12 Likes
sam
(Sam Saffron)
Closed
February 24, 2018, 7:00am
12
This topic was automatically closed after 4 days. New replies are no longer allowed.