@@ -21,50 +21,60 @@ def search_service_results
2121 if resolving_non_matching_remote_account?
2222 [ ResolveAccountService . new . call ( "#{ query_username } @#{ query_domain } " ) ] . compact
2323 else
24- search_results_and_exact_match . compact . uniq . slice ( 0 , limit )
24+ search_results_and_exact_match . compact . uniq
2525 end
2626 end
2727
2828 def resolving_non_matching_remote_account?
29- options [ :resolve ] && !exact_match && !domain_is_local?
29+ offset . zero? && options [ :resolve ] && !exact_match? && !domain_is_local?
3030 end
3131
3232 def search_results_and_exact_match
33- exact = [ exact_match ]
34- return exact if !exact [ 0 ] . nil? && limit == 1
35- exact + search_results . to_a
33+ return search_results . to_a unless offset . zero?
34+
35+ results = [ exact_match ]
36+
37+ return results if exact_match? && limit == 1
38+
39+ results + search_results . to_a
3640 end
3741
3842 def query_blank_or_hashtag?
3943 query . blank? || query . start_with? ( '#' )
4044 end
4145
4246 def split_query_string
43- @_split_query_string ||= query . gsub ( /\A @/ , '' ) . split ( '@' )
47+ @split_query_string ||= query . gsub ( /\A @/ , '' ) . split ( '@' )
4448 end
4549
4650 def query_username
47- @_query_username ||= split_query_string . first || ''
51+ @query_username ||= split_query_string . first || ''
4852 end
4953
5054 def query_domain
51- @_query_domain ||= query_without_split? ? nil : split_query_string . last
55+ @query_domain ||= query_without_split? ? nil : split_query_string . last
5256 end
5357
5458 def query_without_split?
5559 split_query_string . size == 1
5660 end
5761
5862 def domain_is_local?
59- @_domain_is_local ||= TagManager . instance . local_domain? ( query_domain )
63+ @domain_is_local ||= TagManager . instance . local_domain? ( query_domain )
6064 end
6165
6266 def search_from
6367 options [ :following ] && account ? account . following : Account
6468 end
6569
70+ def exact_match?
71+ exact_match . present?
72+ end
73+
6674 def exact_match
67- @_exact_match ||= begin
75+ return @exact_match if defined? ( @exact_match )
76+
77+ @exact_match = begin
6878 if domain_is_local?
6979 search_from . without_suspended . find_local ( query_username )
7080 else
@@ -74,7 +84,7 @@ def exact_match
7484 end
7585
7686 def search_results
77- @_search_results ||= begin
87+ @search_results ||= begin
7888 if account
7989 advanced_search_results
8090 else
@@ -84,11 +94,19 @@ def search_results
8494 end
8595
8696 def advanced_search_results
87- Account . advanced_search_for ( terms_for_query , account , limit , options [ :following ] , offset )
97+ Account . advanced_search_for ( terms_for_query , account , limit_for_non_exact_results , options [ :following ] , offset )
8898 end
8999
90100 def simple_search_results
91- Account . search_for ( terms_for_query , limit , offset )
101+ Account . search_for ( terms_for_query , limit_for_non_exact_results , offset )
102+ end
103+
104+ def limit_for_non_exact_results
105+ if offset . zero? && exact_match?
106+ limit - 1
107+ else
108+ limit
109+ end
92110 end
93111
94112 def terms_for_query
0 commit comments