From 08e5d96a4a07305660044e53657a52f935c3eee3 Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 5 Apr 2023 13:55:37 +0900 Subject: [PATCH] Expand search range --- app/chewy/statuses_index.rb | 5 +++++ app/controllers/api/v2/search_controller.rb | 2 +- app/models/status.rb | 2 ++ app/services/search_service.rb | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 6dd4fb18b0..a185b7ce29 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -47,6 +47,11 @@ class StatusesIndex < Chewy::Index data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } end + crutch :emoji_reactions do |collection| + data = ::EmojiReaction.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end + crutch :reblogs do |collection| data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id) data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } diff --git a/app/controllers/api/v2/search_controller.rb b/app/controllers/api/v2/search_controller.rb index 4d20aeb10f..6098fc6abd 100644 --- a/app/controllers/api/v2/search_controller.rb +++ b/app/controllers/api/v2/search_controller.rb @@ -3,7 +3,7 @@ class Api::V2::SearchController < Api::BaseController include Authorization - RESULTS_LIMIT = 20 + RESULTS_LIMIT = 40 before_action -> { authorize_if_got_token! :read, :'read:search' } before_action :validate_search_params! diff --git a/app/models/status.rb b/app/models/status.rb index f2f71f5415..800147f26a 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -150,12 +150,14 @@ class Status < ApplicationRecord if preloaded.nil? ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id) ids += favourites.joins(:account).merge(Account.local).pluck(:account_id) + ids += emoji_reactions.joins(:account).merge(Account.local).pluck(:account_id) ids += reblogs.joins(:account).merge(Account.local).pluck(:account_id) ids += bookmarks.joins(:account).merge(Account.local).pluck(:account_id) ids += poll.votes.joins(:account).merge(Account.local).pluck(:account_id) if poll.present? else ids += preloaded.mentions[id] || [] ids += preloaded.favourites[id] || [] + ids += preloaded.emoji_reactions[id] || [] ids += preloaded.reblogs[id] || [] ids += preloaded.bookmarks[id] || [] ids += preloaded.votes[id] || [] diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 93b72fa0c4..0d2383a53c 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -35,7 +35,8 @@ class SearchService < BaseService end def perform_statuses_search! - definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })) + # definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })).order(id: :desc) + definition = parsed_query.apply(StatusesIndex).order(id: :desc) definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present?