mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 17:53:44 +08:00
FEATURE: Include advanced search option to include unlisted topics in the results (#27958)
--------- Co-authored-by: Régis Hanol <regis@hanol.fr>
This commit is contained in:
parent
e1f638b0a3
commit
6a3e12a39c
|
@ -935,6 +935,9 @@ class Search
|
||||||
@search_context = user
|
@search_context = user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
|
elsif word =~ /\Ainclude:(invisible|unlisted)\z/i
|
||||||
|
@include_invisible = true
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
found ? nil : word
|
found ? nil : word
|
||||||
|
@ -1113,7 +1116,7 @@ class Search
|
||||||
end
|
end
|
||||||
|
|
||||||
is_topic_search = @search_context.present? && @search_context.is_a?(Topic)
|
is_topic_search = @search_context.present? && @search_context.is_a?(Topic)
|
||||||
posts = posts.where("topics.visible") unless is_topic_search
|
posts = posts.where("topics.visible") unless is_topic_search || @include_invisible
|
||||||
|
|
||||||
if type_filter == "private_messages" || (is_topic_search && @search_context.private_message?)
|
if type_filter == "private_messages" || (is_topic_search && @search_context.private_message?)
|
||||||
posts =
|
posts =
|
||||||
|
|
|
@ -2541,6 +2541,23 @@ RSpec.describe Search do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "include:invisible / include:unlisted" do
|
||||||
|
it "allows including invisible topics in the results" do
|
||||||
|
topic = Fabricate(:topic, title: "I am testing a search", visible: false)
|
||||||
|
post = Fabricate(:post, topic: topic, raw: "this is the first post", post_number: 1)
|
||||||
|
_post2 = Fabricate(:post, topic: topic, raw: "this is the second post", post_number: 2)
|
||||||
|
|
||||||
|
results = Search.execute("testing include:invisible")
|
||||||
|
expect(results.posts.map(&:id)).to eq([post.id])
|
||||||
|
|
||||||
|
results = Search.execute("testing include:unlisted")
|
||||||
|
expect(results.posts.map(&:id)).to eq([post.id])
|
||||||
|
|
||||||
|
results = Search.execute("testing")
|
||||||
|
expect(results.posts).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "ignore_diacritics" do
|
describe "ignore_diacritics" do
|
||||||
before { SiteSetting.search_ignore_accents = true }
|
before { SiteSetting.search_ignore_accents = true }
|
||||||
let!(:post1) { Fabricate(:post, raw: "สวัสดี Rágis hello") }
|
let!(:post1) { Fabricate(:post, raw: "สวัสดี Rágis hello") }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user