mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
BUGFIX: bypass fulltext for search in topic
This commit is contained in:
parent
51709a0a27
commit
af86014fd0
@ -153,12 +153,17 @@ class Search
|
||||
|
||||
def posts_query(limit)
|
||||
posts = Post.includes(:post_search_data, {:topic => :category})
|
||||
.where("post_search_data.search_data @@ #{ts_query}")
|
||||
.where("topics.deleted_at" => nil)
|
||||
.where("topics.visible")
|
||||
.where("topics.archetype <> ?", Archetype.private_message)
|
||||
.references(:post_search_data, {:topic => :category})
|
||||
|
||||
if @search_context.present? && @search_context.is_a?(Topic)
|
||||
posts = posts.where("posts.raw ilike ?", "%#{@term}%")
|
||||
else
|
||||
posts = posts.where("post_search_data.search_data @@ #{ts_query}")
|
||||
end
|
||||
|
||||
# If we have a search context, prioritize those posts first
|
||||
if @search_context.present?
|
||||
|
||||
|
@ -142,12 +142,13 @@ describe Search do
|
||||
topic2 = Fabricate(:topic)
|
||||
|
||||
new_post('this is the other post I am posting', topic2)
|
||||
new_post('this is my fifth post I am posting', topic2)
|
||||
|
||||
post1 = new_post('this is the other post I am posting', topic)
|
||||
post2 = new_post('this is my first post I am posting', topic)
|
||||
post3 = new_post('this is a real long and complicated bla this is my second post I am Posting birds
|
||||
with more stuff bla bla', topic)
|
||||
post4 = new_post('this is my fourth post I am posting', topic)
|
||||
new_post('this is my fifth post I am posting', topic2)
|
||||
|
||||
# update posts_count
|
||||
topic.reload
|
||||
@ -164,6 +165,13 @@ describe Search do
|
||||
"_#{post3.id}",
|
||||
"_#{post4.id}"]
|
||||
|
||||
# stop words should work
|
||||
results = Search.new('this', search_context: post1.topic).execute.find do |r|
|
||||
r[:type] == "topic"
|
||||
end[:results]
|
||||
|
||||
results.length.should == 4
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user