mirror of https://github.com/tootsuite/mastodon
Change searching with # to include account index (#25638)
parent
af54bf52c8
commit
99be47f8b9
|
@ -133,8 +133,12 @@ class AccountSearchService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def must_clause
|
def must_clause
|
||||||
fields = %w(username username.* display_name display_name.*)
|
if options[:start_with_hashtag]
|
||||||
fields << 'text' << 'text.*' if options[:use_searchable_text]
|
fields = %w(text text.*)
|
||||||
|
else
|
||||||
|
fields = %w(username username.* display_name display_name.*)
|
||||||
|
fields << 'text' << 'text.*' if options[:use_searchable_text]
|
||||||
|
end
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,8 @@ class SearchService < BaseService
|
||||||
resolve: @resolve,
|
resolve: @resolve,
|
||||||
offset: @offset,
|
offset: @offset,
|
||||||
use_searchable_text: true,
|
use_searchable_text: true,
|
||||||
following: @following
|
following: @following,
|
||||||
|
start_with_hashtag: @query.start_with?('#')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -91,11 +92,11 @@ class SearchService < BaseService
|
||||||
def full_text_searchable?
|
def full_text_searchable?
|
||||||
return false unless Chewy.enabled?
|
return false unless Chewy.enabled?
|
||||||
|
|
||||||
statuses_search? && !@account.nil? && !((@query.start_with?('#') || @query.include?('@')) && !@query.include?(' '))
|
statuses_search? && !@account.nil? && !(@query.include?('@') && !@query.include?(' '))
|
||||||
end
|
end
|
||||||
|
|
||||||
def account_searchable?
|
def account_searchable?
|
||||||
account_search? && !(@query.start_with?('#') || (@query.include?('@') && @query.include?(' ')))
|
account_search? && !(@query.include?('@') && @query.include?(' '))
|
||||||
end
|
end
|
||||||
|
|
||||||
def hashtag_searchable?
|
def hashtag_searchable?
|
||||||
|
|
|
@ -68,7 +68,7 @@ describe SearchService, type: :service do
|
||||||
allow(AccountSearchService).to receive(:new).and_return(service)
|
allow(AccountSearchService).to receive(:new).and_return(service)
|
||||||
|
|
||||||
results = subject.call(query, nil, 10)
|
results = subject.call(query, nil, 10)
|
||||||
expect(service).to have_received(:call).with(query, nil, limit: 10, offset: 0, resolve: false, use_searchable_text: true, following: false)
|
expect(service).to have_received(:call).with(query, nil, limit: 10, offset: 0, resolve: false, start_with_hashtag: false, use_searchable_text: true, following: false)
|
||||||
expect(results).to eq empty_results.merge(accounts: [account])
|
expect(results).to eq empty_results.merge(accounts: [account])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -92,15 +92,6 @@ describe SearchService, type: :service do
|
||||||
expect(Tag).to_not have_received(:search_for)
|
expect(Tag).to_not have_received(:search_for)
|
||||||
expect(results).to eq empty_results
|
expect(results).to eq empty_results
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not include account when starts with # character' do
|
|
||||||
query = '#tag'
|
|
||||||
allow(AccountSearchService).to receive(:new)
|
|
||||||
|
|
||||||
results = subject.call(query, nil, 10)
|
|
||||||
expect(AccountSearchService).to_not have_received(:new)
|
|
||||||
expect(results).to eq empty_results
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue