Ensure the mentioning scope search works
Include the filter by accessible board ids to avoid large joins from the search_index table. Drop the unused search scope.
This commit is contained in:
committed by
Mike Dalessio
parent
a41085fe00
commit
ddd7fe082a
@@ -20,7 +20,7 @@ class Prompts::CardsController < ApplicationController
|
||||
|
||||
def search_cards
|
||||
published_cards
|
||||
.mentioning(params[:filter])
|
||||
.mentioning(params[:filter], board_ids: Current.user.board_ids)
|
||||
.reverse_chronologically
|
||||
.limit(MAX_RESULTS)
|
||||
end
|
||||
|
||||
@@ -4,11 +4,17 @@ module Card::Searchable
|
||||
included do
|
||||
include ::Searchable
|
||||
|
||||
scope :mentioning, ->(query) do
|
||||
cards = Card.search(query).select(:id).to_sql
|
||||
comments = Comment.search(query).select(:id).to_sql
|
||||
scope :mentioning, ->(query, board_ids:) do
|
||||
query = Search::Query.wrap(query)
|
||||
|
||||
left_joins(:comments).where("cards.id in (#{cards}) or comments.id in (#{comments})").distinct
|
||||
if query.valid?
|
||||
joins("INNER JOIN search_index ON search_index.card_id = cards.id AND search_index.board_id = cards.board_id")
|
||||
.where("search_index.board_id IN (?)", board_ids)
|
||||
.where("MATCH(search_index.content, search_index.title) AGAINST(? IN BOOLEAN MODE)", query.to_s)
|
||||
.distinct
|
||||
else
|
||||
none
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,18 +5,6 @@ module Searchable
|
||||
after_create_commit :create_in_search_index
|
||||
after_update_commit :update_in_search_index
|
||||
after_destroy_commit :remove_from_search_index
|
||||
|
||||
scope :search, ->(query) do
|
||||
query = Search::Query.wrap(query)
|
||||
|
||||
base = joins("INNER JOIN search_index ON search_index.searchable_type = '#{name}' AND search_index.searchable_id = #{table_name}.id")
|
||||
|
||||
if query.valid?
|
||||
base.where("MATCH(search_index.content, search_index.title) AGAINST(? IN BOOLEAN MODE)", query.to_s)
|
||||
else
|
||||
base.none
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reindex
|
||||
|
||||
@@ -33,7 +33,7 @@ class Filter < ApplicationRecord
|
||||
result = result.closed_at_window(closure_window) if closure_window
|
||||
result = result.closed_by(closers) if closers.present?
|
||||
result = terms.reduce(result) do |result, term|
|
||||
result.mentioning(term)
|
||||
result.mentioning(term, board_ids: creator.board_ids)
|
||||
end
|
||||
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user