Fix bad search type heuristic (#26673)

This commit is contained in:
Eugen Rochko 2023-08-28 17:08:37 +02:00 committed by GitHub
parent 0cce7fb617
commit 2304cc6456
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 17 deletions

View file

@ -17,7 +17,7 @@ class SearchService < BaseService
results.merge!(url_resource_results) unless url_resource.nil? || @offset.positive? || (@options[:type].present? && url_resource_symbol != @options[:type].to_sym) results.merge!(url_resource_results) unless url_resource.nil? || @offset.positive? || (@options[:type].present? && url_resource_symbol != @options[:type].to_sym)
elsif @query.present? elsif @query.present?
results[:accounts] = perform_accounts_search! if account_searchable? results[:accounts] = perform_accounts_search! if account_searchable?
results[:statuses] = perform_statuses_search! if full_text_searchable? results[:statuses] = perform_statuses_search! if status_searchable?
results[:hashtags] = perform_hashtags_search! if hashtag_searchable? results[:hashtags] = perform_hashtags_search! if hashtag_searchable?
end end
end end
@ -79,18 +79,16 @@ class SearchService < BaseService
url_resource.class.name.downcase.pluralize.to_sym url_resource.class.name.downcase.pluralize.to_sym
end end
def full_text_searchable? def status_searchable?
return false unless Chewy.enabled? Chewy.enabled? && status_search? && @account.present?
statuses_search? && !@account.nil? && !(@query.include?('@') && !@query.include?(' '))
end end
def account_searchable? def account_searchable?
account_search? && !(@query.include?('@') && @query.include?(' ')) account_search?
end end
def hashtag_searchable? def hashtag_searchable?
hashtag_search? && !@query.include?('@') hashtag_search?
end end
def account_search? def account_search?
@ -101,7 +99,7 @@ class SearchService < BaseService
@options[:type].blank? || @options[:type] == 'hashtags' @options[:type].blank? || @options[:type] == 'hashtags'
end end
def statuses_search? def status_search?
@options[:type].blank? || @options[:type] == 'statuses' @options[:type].blank? || @options[:type] == 'statuses'
end end
end end

View file

@ -83,15 +83,6 @@ describe SearchService, type: :service do
expect(Tag).to have_received(:search_for).with('tag', 10, 0, exclude_unreviewed: nil) expect(Tag).to have_received(:search_for).with('tag', 10, 0, exclude_unreviewed: nil)
expect(results).to eq empty_results.merge(hashtags: [tag]) expect(results).to eq empty_results.merge(hashtags: [tag])
end end
it 'does not include tag when starts with @ character' do
query = '@username'
allow(Tag).to receive(:search_for)
results = subject.call(query, nil, 10)
expect(Tag).to_not have_received(:search_for)
expect(results).to eq empty_results
end
end end
end end
end end