A platform for community discussion. Free, open, simple.
FIX: advanced search ordering broken when using tags
Penar Musaraj70d74f8fc17f
diff --git a/lib/search.rb b/lib/search.rbindex 3cd0a20a143..80c6df50532 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -508,7 +508,7 @@ class SearchWHERE tt.tag_id = tags.idGROUP BY tt.topic_idHAVING to_tsvector(#{default_ts_config}, array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery(#{default_ts_config}, ?)- )", tags.join('&')).order("id")+ )", tags.join('&'))elsetags = match.split(",")@@ -516,7 +516,7 @@ class SearchSELECT DISTINCT(tt.topic_id)FROM topic_tags tt, tagsWHERE tt.tag_id = tags.id AND tags.name IN (?)- )", tags).order("id")+ )", tags)endenddiff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex 1b59d8a1186..912415a4a12 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -894,6 +894,22 @@ describe Search doexpect(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+endit "can find posts which contains filetypes" do