Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change searching with # to include account index #25638

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/services/account_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ def time_distance_function
end

def must_clause
fields = %w(username username.* display_name display_name.*)
fields << 'text' << 'text.*' if options[:use_searchable_text]
if options[:start_with_hashtag]
fields = %w(text text.*)
else
fields = %w(username username.* display_name display_name.*)
fields << 'text' << 'text.*' if options[:use_searchable_text]
end

[
{
Expand Down
7 changes: 4 additions & 3 deletions app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def perform_accounts_search!
resolve: @resolve,
offset: @offset,
use_searchable_text: true,
following: @following
following: @following,
start_with_hashtag: @query.start_with?('#')
)
end

Expand Down Expand Up @@ -91,11 +92,11 @@ def url_resource_symbol
def full_text_searchable?
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

def account_searchable?
account_search? && !(@query.start_with?('#') || (@query.include?('@') && @query.include?(' ')))
account_search? && !(@query.include?('@') && @query.include?(' '))
end

def hashtag_searchable?
Expand Down
11 changes: 1 addition & 10 deletions spec/services/search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
allow(AccountSearchService).to receive(:new).and_return(service)

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])
end
end
Expand All @@ -92,15 +92,6 @@
expect(Tag).to_not have_received(:search_for)
expect(results).to eq empty_results
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
Expand Down