mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
BUGFIX: bypass fulltext for search in topic
This commit is contained in:
parent
51709a0a27
commit
af86014fd0
2 changed files with 15 additions and 2 deletions
|
@ -153,12 +153,17 @@ class Search
|
||||||
|
|
||||||
def posts_query(limit)
|
def posts_query(limit)
|
||||||
posts = Post.includes(:post_search_data, {:topic => :category})
|
posts = Post.includes(:post_search_data, {:topic => :category})
|
||||||
.where("post_search_data.search_data @@ #{ts_query}")
|
|
||||||
.where("topics.deleted_at" => nil)
|
.where("topics.deleted_at" => nil)
|
||||||
.where("topics.visible")
|
.where("topics.visible")
|
||||||
.where("topics.archetype <> ?", Archetype.private_message)
|
.where("topics.archetype <> ?", Archetype.private_message)
|
||||||
.references(:post_search_data, {:topic => :category})
|
.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 we have a search context, prioritize those posts first
|
||||||
if @search_context.present?
|
if @search_context.present?
|
||||||
|
|
||||||
|
|
|
@ -142,12 +142,13 @@ describe Search do
|
||||||
topic2 = Fabricate(:topic)
|
topic2 = Fabricate(:topic)
|
||||||
|
|
||||||
new_post('this is the other post I am posting', topic2)
|
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)
|
post1 = new_post('this is the other post I am posting', topic)
|
||||||
post2 = new_post('this is my first 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
|
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)
|
with more stuff bla bla', topic)
|
||||||
post4 = new_post('this is my fourth post I am posting', 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
|
# update posts_count
|
||||||
topic.reload
|
topic.reload
|
||||||
|
@ -164,6 +165,13 @@ describe Search do
|
||||||
"_#{post3.id}",
|
"_#{post3.id}",
|
||||||
"_#{post4.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue