FEATURE: new setting to prioritize open topics in search

This commit is contained in:
Arpit Jalan 2017-06-01 23:58:40 +05:30
parent b4060778d9
commit b8a87a0996
4 changed files with 24 additions and 0 deletions

View File

@ -938,6 +938,7 @@ en:
search_tokenize_chinese_japanese_korean: "Force search to tokenize Chinese/Japanese/Korean even on non CJK sites"
search_prefer_recent_posts: "If searching your large forum is slow, this option tries an index of more recent posts first"
search_recent_posts_size: "How many recent posts to keep in the index"
prioritize_open_topics_in_search: "Closed topics in search results will show up after open topics"
allow_uncategorized_topics: "Allow topics to be created without a category. WARNING: If there are any uncategorized topics, you must recategorize them before turning this off."
allow_duplicate_topic_titles: "Allow topics with identical, duplicate titles."
unique_posts_mins: "How many minutes before a user can make a post with the same content again"

View File

@ -1132,6 +1132,7 @@ search:
search_tokenize_chinese_japanese_korean: false
search_prefer_recent_posts: false
search_recent_posts_size: 100000
prioritize_open_topics_in_search: false
uncategorized:
version_checks:

View File

@ -694,6 +694,8 @@ class Search
posts = posts.order("posts.like_count DESC")
end
else
posts = posts.order("topics.closed") if SiteSetting.prioritize_open_topics_in_search
posts = posts.order("TS_RANK_CD(TO_TSVECTOR(#{query_locale}, topics.title), #{ts_query}) DESC")
data_ranking = "TS_RANK_CD(post_search_data.search_data, #{ts_query})"

View File

@ -662,6 +662,26 @@ describe Search do
expect(Search.execute('Topic order:latest_topic').posts.map(&:id)).to eq([latest_irelevant_topic_post.id, old_relevant_topic_post.id])
end
context 'can prioritize open topics in search' do
before do
open_topic = Fabricate(:topic, title: 'Open Topic, testing prioritize open topics setting')
closed_topic = Fabricate(:topic, title: 'Closed Topic, testing prioritize open topics setting', closed: true)
@open_irrelevant_topic_post = Fabricate(:post, topic: open_topic, raw: 'Not Relevant')
@closed_relevant_topic_post = Fabricate(:post, topic: closed_topic, raw: 'Relevant Topic')
end
it "when prioritize_open_topics_in_search is disabled" do
SiteSetting.prioritize_open_topics_in_search = false
expect(Search.execute('Topic').posts.map(&:id)).to eq([@closed_relevant_topic_post.id, @open_irrelevant_topic_post.id])
end
it "when prioritize_open_topics_in_search is enabled" do
SiteSetting.prioritize_open_topics_in_search = true
expect(Search.execute('Topic').posts.map(&:id)).to eq([@open_irrelevant_topic_post.id, @closed_relevant_topic_post.id])
end
end
it 'can tokenize dots' do
post = Fabricate(:post, raw: 'Will.2000 Will.Bob.Bill...')
expect(Search.execute('bill').posts.map(&:id)).to eq([post.id])