FIX: advanced search ordering broken when using tags

This commit is contained in:
Penar Musaraj 2018-09-28 05:27:08 -04:00 committed by Sam
parent a2b6eed284
commit 70d74f8fc1
2 changed files with 18 additions and 2 deletions

View File

@ -508,7 +508,7 @@ class Search
WHERE tt.tag_id = tags.id
GROUP BY tt.topic_id
HAVING to_tsvector(#{default_ts_config}, array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery(#{default_ts_config}, ?)
)", tags.join('&')).order("id")
)", tags.join('&'))
else
tags = match.split(",")
@ -516,7 +516,7 @@ class Search
SELECT DISTINCT(tt.topic_id)
FROM topic_tags tt, tags
WHERE tt.tag_id = tags.id AND tags.name IN (?)
)", tags).order("id")
)", tags)
end
end

View File

@ -894,6 +894,22 @@ describe Search do
expect(Search.execute('tags:eggs -tags:lunch,sandwiches').posts)
.to contain_exactly(post1, post2)
end
it 'orders posts correctly when combining tags with categories or terms' do
cat1 = Fabricate(:category, name: 'food')
topic6 = Fabricate(:topic, tags: [tag1, tag2], category: cat1)
topic7 = Fabricate(:topic, tags: [tag1, tag2, tag3], category: cat1)
post7 = Fabricate(:post, topic: topic6, raw: "Wakey, wakey, eggs and bakey.", like_count: 5)
post8 = Fabricate(:post, topic: topic7, raw: "Bakey, bakey, eggs to makey.", like_count: 2)
expect(Search.execute('bakey tags:lunch order:latest').posts.map(&:id))
.to eq([post8.id, post7.id])
expect(Search.execute('#food tags:lunch order:latest').posts.map(&:id))
.to eq([post8.id, post7.id])
expect(Search.execute('#food tags:lunch order:likes').posts.map(&:id))
.to eq([post7.id, post8.id])
end
end
it "can find posts which contains filetypes" do