A platform for community discussion. Free, open, simple.
FIX: Include oneboxed content in topic search results (#37035)
Régis Hanolde7680c8c95c
diff --git a/lib/search.rb b/lib/search.rbindex b321be5668b..78c3e1d9e72 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -1242,13 +1242,12 @@ class Searchif is_topic_searchterm_without_quote = @termterm_without_quote = $1 if @term =~ /"(.+)"/-term_without_quote = $1 if @term =~ /'(.+)'/posts = posts.joins("JOIN users u ON u.id = posts.user_id")posts =posts.where(- "posts.raw || ' ' || u.username || ' ' || COALESCE(u.name, '') ilike ?",+ "posts.raw || ' ' || post_search_data.raw_data || ' ' || u.username || ' ' || COALESCE(u.name, '') ILIKE ?","%#{term_without_quote}%",)else@@ -1258,7 +1257,7 @@ class Searchexact_terms.each do |exact|posts =- posts.where("posts.raw ilike :exact OR topics.title ilike :exact", exact: "%#{exact}%")+ posts.where("posts.raw ILIKE :exact OR topics.title ILIKE :exact", exact: "%#{exact}%")endendend@@ -1285,16 +1284,14 @@ class Search.pluck(:id).push(@search_context.id)- posts.where("topics.category_id in (?)", category_ids)+ posts.where("topics.category_id IN (?)", category_ids)elsif is_topic_searchposts = posts.where("topics.id = ?", @search_context.id)posts = posts.order("posts.post_number ASC") unless @orderpostselsif @search_context.is_a?(Tag)- posts =- posts.joins("LEFT JOIN topic_tags ON topic_tags.topic_id = topics.id").joins(- "LEFT JOIN tags ON tags.id = topic_tags.tag_id",- )+ posts = posts.joins("LEFT JOIN topic_tags ON topic_tags.topic_id = topics.id")+ posts = posts.joins("LEFT JOIN tags ON tags.id = topic_tags.tag_id")posts.where("tags.id = ?", @search_context.id)endelse@@ -1316,14 +1313,8 @@ class Searchendend- posts =- apply_order(- posts,- aggregate_search: aggregate_search,- allow_relevance_search: !is_topic_search,- type_filter: type_filter,- )-+ allow_relevance_search = !is_topic_search+ posts = apply_order(posts, aggregate_search:, allow_relevance_search:, type_filter:)posts = posts.offset(offset)posts.limit(limit)enddiff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rbindex 8819866cfc9..e0b6e4d98b8 100644--- a/spec/lib/search_spec.rb+++ b/spec/lib/search_spec.rb@@ -1412,6 +1412,14 @@ RSpec.describe Search doresults = Search.execute("discourse", search_context: topic)expect(results.posts.length).to eq(1)end++ it "finds content only present in cooked HTML" do+ post = new_post("check out this link")+ post.post_search_data.update!(raw_data: "check out this link Example Site Title")++ results = Search.execute("Example Site Title", search_context: post.topic)+ expect(results.posts.map(&:id)).to eq([post.id])+ endendcontext "when searching the OP" do