fix: new endpoint for the text search
This commit is contained in:
parent
a8600d79f4
commit
c03a6602f3
6 changed files with 31 additions and 7 deletions
|
@ -11,6 +11,10 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
|||
@conversations_count = result[:count]
|
||||
end
|
||||
|
||||
def text_search
|
||||
@result = conversation_finder.search
|
||||
end
|
||||
|
||||
def meta
|
||||
result = conversation_finder.perform
|
||||
@conversations_count = result[:count]
|
||||
|
|
|
@ -34,9 +34,7 @@ class ConversationFinder
|
|||
filter_by_assignee_type
|
||||
|
||||
{
|
||||
conversations: @conversations,
|
||||
contacts: @contacts,
|
||||
messages: @messages
|
||||
conversations: conversations,
|
||||
count: {
|
||||
mine_count: mine_count,
|
||||
assigned_count: assigned_count,
|
||||
|
@ -105,7 +103,7 @@ class ConversationFinder
|
|||
@conversations
|
||||
end
|
||||
|
||||
def filter_by_query
|
||||
def search
|
||||
{
|
||||
messages: filter_messages,
|
||||
conversations: filter_conversations,
|
||||
|
@ -113,9 +111,17 @@ class ConversationFinder
|
|||
}
|
||||
end
|
||||
|
||||
def filter_by_query
|
||||
allowed_message_types = [Message.message_types[:incoming], Message.message_types[:outgoing]]
|
||||
@conversations = conversations.joins(:messages).where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||
.where(messages: { message_type: allowed_message_types }).includes(:messages)
|
||||
.where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||
.where(messages: { message_type: allowed_message_types })
|
||||
end
|
||||
|
||||
def filter_conversations
|
||||
conversation_ids = PgSearch.multisearch("#{@params[:q]}%").where(account_id: @current_account,
|
||||
searchable_type: 'Conversation').pluck(:searchable_id)
|
||||
searchable_type: 'Conversation').pluck(:searchable_id)
|
||||
@conversations = Conversation.where(id: conversation_ids)
|
||||
end
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ module MultiSearchableHelpers
|
|||
end
|
||||
|
||||
def contacts_pg_search_records
|
||||
contacts_pg_search_records ||= PgSearch::Document.where(
|
||||
PgSearch::Document.where(
|
||||
searchable_type: 'Contact',
|
||||
searchable_id: contact_id,
|
||||
account_id: account_id
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
json.payload do
|
||||
json.array! @result[:conversations] do |conversation|
|
||||
json.partial! 'api/v1/models/conversation', formats: [:json], conversation: conversation
|
||||
end
|
||||
|
||||
json.array! @result[:contacts] do |contact|
|
||||
json.partial! 'api/v1/models/contact', formats: [:json], resource: contact
|
||||
end
|
||||
|
||||
json.array! @result[:messages] do |message|
|
||||
json.partial! 'api/v1/models/message', formats: [:json], message: message
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@ json.inbox do
|
|||
json.channel_type conversation.inbox.channel_type
|
||||
end
|
||||
json.messages do
|
||||
json.array! conversation.messages.last(1) do |message|
|
||||
json.array! conversation.messages do |message|
|
||||
json.content message.content
|
||||
json.id message.id
|
||||
json.sender_name message.sender.name if message.sender
|
||||
|
|
|
@ -71,6 +71,7 @@ Rails.application.routes.draw do
|
|||
get :meta
|
||||
get :search
|
||||
post :filter
|
||||
get :text_search
|
||||
end
|
||||
scope module: :conversations do
|
||||
resources :messages, only: [:index, :create, :destroy]
|
||||
|
|
Loading…
Reference in a new issue