about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-08-12 23:01:19 +0200
committerGitHub <noreply@github.com>2019-08-12 23:01:19 +0200
commitcf421bafdf644f8c8a44b4f06f82841cbd568cdf (patch)
tree4d1f3b2c9bdcadcf0fe53372a75ba54c0c06875a /app/services
parentaa485d6f055b93fd7a9df8b47ed96122b38af39e (diff)
parentcfca28bc874125e63e7e1a3c96d94bd5a7eca108 (diff)
Merge pull request #1196 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/services')
-rw-r--r--app/services/account_search_service.rb44
1 files changed, 31 insertions, 13 deletions
diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb
index 7bdffbbd2..e1874d045 100644
--- a/app/services/account_search_service.rb
+++ b/app/services/account_search_service.rb
@@ -21,18 +21,22 @@ class AccountSearchService < BaseService
     if resolving_non_matching_remote_account?
       [ResolveAccountService.new.call("#{query_username}@#{query_domain}")].compact
     else
-      search_results_and_exact_match.compact.uniq.slice(0, limit)
+      search_results_and_exact_match.compact.uniq
     end
   end
 
   def resolving_non_matching_remote_account?
-    options[:resolve] && !exact_match && !domain_is_local?
+    offset.zero? && options[:resolve] && !exact_match? && !domain_is_local?
   end
 
   def search_results_and_exact_match
-    exact = [exact_match]
-    return exact if !exact[0].nil? && limit == 1
-    exact + search_results.to_a
+    return search_results.to_a unless offset.zero?
+
+    results = [exact_match]
+
+    return results if exact_match? && limit == 1
+
+    results + search_results.to_a
   end
 
   def query_blank_or_hashtag?
@@ -40,15 +44,15 @@ class AccountSearchService < BaseService
   end
 
   def split_query_string
-    @_split_query_string ||= query.gsub(/\A@/, '').split('@')
+    @split_query_string ||= query.gsub(/\A@/, '').split('@')
   end
 
   def query_username
-    @_query_username ||= split_query_string.first || ''
+    @query_username ||= split_query_string.first || ''
   end
 
   def query_domain
-    @_query_domain ||= query_without_split? ? nil : split_query_string.last
+    @query_domain ||= query_without_split? ? nil : split_query_string.last
   end
 
   def query_without_split?
@@ -56,15 +60,21 @@ class AccountSearchService < BaseService
   end
 
   def domain_is_local?
-    @_domain_is_local ||= TagManager.instance.local_domain?(query_domain)
+    @domain_is_local ||= TagManager.instance.local_domain?(query_domain)
   end
 
   def search_from
     options[:following] && account ? account.following : Account
   end
 
+  def exact_match?
+    exact_match.present?
+  end
+
   def exact_match
-    @_exact_match ||= begin
+    return @exact_match if defined?(@exact_match)
+
+    @exact_match = begin
       if domain_is_local?
         search_from.without_suspended.find_local(query_username)
       else
@@ -74,7 +84,7 @@ class AccountSearchService < BaseService
   end
 
   def search_results
-    @_search_results ||= begin
+    @search_results ||= begin
       if account
         advanced_search_results
       else
@@ -84,11 +94,19 @@ class AccountSearchService < BaseService
   end
 
   def advanced_search_results
-    Account.advanced_search_for(terms_for_query, account, limit, options[:following], offset)
+    Account.advanced_search_for(terms_for_query, account, limit_for_non_exact_results, options[:following], offset)
   end
 
   def simple_search_results
-    Account.search_for(terms_for_query, limit, offset)
+    Account.search_for(terms_for_query, limit_for_non_exact_results, offset)
+  end
+
+  def limit_for_non_exact_results
+    if offset.zero? && exact_match?
+      limit - 1
+    else
+      limit
+    end
   end
 
   def terms_for_query