FIX: in:title search should only search through topic first posts.

This commit is contained in:
Guo Xiang Tan 2020-07-16 12:21:19 +08:00
parent 84de643c04
commit af87911178
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
2 changed files with 5 additions and 9 deletions

View File

@ -847,6 +847,7 @@ class Search
# C is for tags
# D is for cooked
weights = @in_title ? 'A' : (SiteSetting.tagging_enabled ? 'ABCD' : 'ABD')
posts = posts.where(post_number: 1) if @in_title
posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")
exact_terms = @term.scan(Regexp.new(PHRASE_MATCH_REGEXP_PATTERN)).flatten

View File

@ -1513,19 +1513,14 @@ describe Search do
context 'in:title' do
it 'allows for search in title' do
topic = Fabricate(:topic, title: 'I am testing a title search')
_post = Fabricate(:post, topic: topic, raw: 'this is the first post')
post2 = Fabricate(:post, topic: topic, raw: 'this is the second post', post_number: 2)
post = Fabricate(:post, topic: topic, raw: 'this is the first post', post_number: 1)
results = Search.execute('title in:title')
expect(results.posts.length).to eq(1)
results = Search.execute('title t')
expect(results.posts.length).to eq(1)
expect(results.posts.map(&:id)).to eq([post.id])
results = Search.execute('first in:title')
expect(results.posts.length).to eq(0)
results = Search.execute('first t')
expect(results.posts.length).to eq(0)
expect(results.posts).to eq([])
end
it 'works irrespective of the order' do