A platform for community discussion. Free, open, simple.
FIX: search topic:1 filter excludes topic with ID 1
Jake Goldsborough130a4bf84d86
diff --git a/lib/search.rb b/lib/search.rbindex 58440fe99e5..5f736717930 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -1020,7 +1020,7 @@ class Searchnilelsif word =~ /\Atopic:(\d+)\z/itopic_id = $1.to_i- if topic_id > 1+ if topic_id > 0topic = Topic.find_by(id: topic_id)@search_context = topic if @guardian.can_see?(topic)enddiff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rbindex a19f4077444..d29890442f6 100644--- a/spec/lib/search_spec.rb+++ b/spec/lib/search_spec.rb@@ -2719,6 +2719,20 @@ RSpec.describe Search doexpect(Search.execute("Topic max_views:150").posts.map(&:id)).to eq([post.id])end+ it "returns every matching post from topic 1 without including other topics" do+ topic.update!(id: 1)+ posts = [+ Fabricate(:post, topic:, raw: "Widgets need a reset after updating"),+ Fabricate(:post, topic:, raw: "Another widget tip: clear the cache"),+ ]+ other_post = Fabricate(:post, raw: "Another widget topic")+ [*posts, other_post].each { |post| SearchIndexer.index(post, force: true) }++ results = Search.execute("widget topic:1", search_type: :full_page)++ expect(results.posts.map(&:id)).to contain_exactly(*posts.map(&:id))+ end+it "can order by likes" doraw = "Foo bar lorem ipsum"topic = Fabricate(:topic)