gerhard
(Gerhard Schlager)
4월 15, 2015, 2:47오후
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개의 좋아요
sam
(Sam Saffron)
4월 15, 2015, 10:39오후
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개의 좋아요
nukeador
(Nukeador)
11월 2, 2017, 6:00오후
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개의 좋아요
Yeah I would like to have this. Anyone who is interested we can fund this work cc @cpradio who may have advice.
6개의 좋아요
pmusaraj
(Penar Musaraj)
11월 6, 2017, 2:11오후
5
I will take a stab at this, see if I can figure it out.
7개의 좋아요
cpradio
(cpradio)
11월 6, 2017, 2:57오후
6
Only advice I have is pay attention to the tokenizer, as I’m fairly certain that is something you’ll be utilizing.
5개의 좋아요
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개의 좋아요
erlend_sh
(Erlend Sogge Heggen)
1월 25, 2018, 11:18오전
8
You’re clear to work on this. @pmusaraj is working with us on other stuff.
5개의 좋아요
pmusaraj
(Penar Musaraj)
1월 25, 2018, 12:12오후
9
Yes, that would be great (I couldn’t figure this out).
4개의 좋아요
Pull Request adding this:
master ← jorgemanrubia:search-only-in-title
opened 12:59PM - 27 Jan 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개의 좋아요
sam
(Sam Saffron)
2월 20, 2018, 4:39오전
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개의 좋아요
sam
(Sam Saffron)
에 닫힘
2월 24, 2018, 7:00오전
12
This topic was automatically closed after 4 days. New replies are no longer allowed.