about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-26 13:00:43 +0200
committerGitHub <noreply@github.com>2022-10-26 13:00:43 +0200
commit7d25f72b9fb5f2940b998579da00a11f8a65fb40 (patch)
treec5634224fa1f391d0881160203df28f1bf1e0264
parentbf0ab3e0fac54515c13beef4ec09b0455f1bce67 (diff)
Fix negatives values in search index causing queries to fail (#19464)
-rw-r--r--app/services/account_search_service.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb
index 35b2e05f5..de1dc7b8e 100644
--- a/app/services/account_search_service.rb
+++ b/app/services/account_search_service.rb
@@ -105,7 +105,7 @@ class AccountSearchService < BaseService
     {
       script_score: {
         script: {
-          source: "(doc['followers_count'].value + 0.0) / (doc['followers_count'].value + doc['following_count'].value + 1)",
+          source: "(Math.max(doc['followers_count'].value, 0) + 0.0) / (Math.max(doc['followers_count'].value, 0) + Math.max(doc['following_count'].value, 0) + 1)",
         },
       },
     }
@@ -113,10 +113,10 @@ class AccountSearchService < BaseService
 
   def followers_score_function
     {
-      field_value_factor: {
-        field: 'followers_count',
-        modifier: 'log2p',
-        missing: 0,
+      script_score: {
+        script: {
+          source: "log2p(Math.max(doc['followers_count'].value, 0))",
+        },
       },
     }
   end