mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Search by topic_id should not be restricted by SiteSetting.min_search_term_length
.
This commit is contained in:
parent
96267f0845
commit
e3ac6585bd
3 changed files with 39 additions and 21 deletions
|
@ -52,7 +52,8 @@ class SearchController < ApplicationController
|
||||||
search_args[:include_blurbs] = params[:include_blurbs] == "true" if params[:include_blurbs].present?
|
search_args[:include_blurbs] = params[:include_blurbs] == "true" if params[:include_blurbs].present?
|
||||||
search_args[:search_for_id] = true if params[:search_for_id].present?
|
search_args[:search_for_id] = true if params[:search_for_id].present?
|
||||||
|
|
||||||
context,type = lookup_search_context
|
context, type = lookup_search_context
|
||||||
|
|
||||||
if context
|
if context
|
||||||
search_args[:search_context] = context
|
search_args[:search_context] = context
|
||||||
search_args[:type_filter] = type if type
|
search_args[:type_filter] = type if type
|
||||||
|
|
|
@ -201,7 +201,6 @@ class Search
|
||||||
|
|
||||||
# Query a term
|
# Query a term
|
||||||
def execute
|
def execute
|
||||||
|
|
||||||
if SiteSetting.log_search_queries?
|
if SiteSetting.log_search_queries?
|
||||||
status, search_log_id = SearchLog.log(
|
status, search_log_id = SearchLog.log(
|
||||||
term: @term,
|
term: @term,
|
||||||
|
@ -212,7 +211,7 @@ class Search
|
||||||
@results.search_log_id = search_log_id unless status == :error
|
@results.search_log_id = search_log_id unless status == :error
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @filters.present?
|
unless @filters.present? || @opts[:search_for_id]
|
||||||
min_length = @opts[:min_search_term_length] || SiteSetting.min_search_term_length
|
min_length = @opts[:min_search_term_length] || SiteSetting.min_search_term_length
|
||||||
terms = (@term || '').split(/\s(?=(?:[^"]|"[^"]*")*$)/).reject {|t| t.length < min_length }
|
terms = (@term || '').split(/\s(?=(?:[^"]|"[^"]*")*$)/).reject {|t| t.length < min_length }
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,30 @@ describe SearchController do
|
||||||
expect(data['users'][0]['id']).to eq(user.id)
|
expect(data['users'][0]['id']).to eq(user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can search for id" do
|
context 'searching by topic id' do
|
||||||
|
it 'should not be restricted by minimum search term length' do
|
||||||
|
SiteSetting.min_search_term_length = 20000
|
||||||
|
|
||||||
|
post = Fabricate(:post)
|
||||||
|
|
||||||
|
xhr(
|
||||||
|
:get,
|
||||||
|
:query,
|
||||||
|
term: post.topic_id,
|
||||||
|
type_filter: 'topic',
|
||||||
|
search_for_id: true
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
data = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(data['topics'][0]['id']).to eq(post.topic_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return the right result" do
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
my_post = Fabricate(:post, raw: "#{user.username} is a cool person")
|
my_post = Fabricate(:post, raw: "#{user.username} is a cool person")
|
||||||
|
|
||||||
xhr(
|
xhr(
|
||||||
:get,
|
:get,
|
||||||
:query,
|
:query,
|
||||||
|
@ -47,17 +68,14 @@ describe SearchController do
|
||||||
type_filter: 'topic',
|
type_filter: 'topic',
|
||||||
search_for_id: true
|
search_for_id: true
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
unless (data && data['topics'] && data['topics'][0] && data['topics'][0]['id'])
|
|
||||||
puts "FLAKY TEST"
|
|
||||||
p data
|
|
||||||
p my_post.topic
|
|
||||||
p my_post
|
|
||||||
end
|
|
||||||
expect(data['topics'][0]['id']).to eq(my_post.topic_id)
|
expect(data['topics'][0]['id']).to eq(my_post.topic_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "#query" do
|
context "#query" do
|
||||||
it "logs the search term" do
|
it "logs the search term" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue