fix: new endpoint for the text search
This commit is contained in:
parent
4aec41bd72
commit
44c0c92f83
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]
|
@conversations_count = result[:count]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def text_search
|
||||||
|
@result = conversation_finder.search
|
||||||
|
end
|
||||||
|
|
||||||
def meta
|
def meta
|
||||||
result = conversation_finder.perform
|
result = conversation_finder.perform
|
||||||
@conversations_count = result[:count]
|
@conversations_count = result[:count]
|
||||||
|
|
|
@ -34,9 +34,7 @@ class ConversationFinder
|
||||||
filter_by_assignee_type
|
filter_by_assignee_type
|
||||||
|
|
||||||
{
|
{
|
||||||
conversations: @conversations,
|
conversations: conversations,
|
||||||
contacts: @contacts,
|
|
||||||
messages: @messages
|
|
||||||
count: {
|
count: {
|
||||||
mine_count: mine_count,
|
mine_count: mine_count,
|
||||||
assigned_count: assigned_count,
|
assigned_count: assigned_count,
|
||||||
|
@ -105,7 +103,7 @@ class ConversationFinder
|
||||||
@conversations
|
@conversations
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_by_query
|
def search
|
||||||
{
|
{
|
||||||
messages: filter_messages,
|
messages: filter_messages,
|
||||||
conversations: filter_conversations,
|
conversations: filter_conversations,
|
||||||
|
@ -113,9 +111,17 @@ class ConversationFinder
|
||||||
}
|
}
|
||||||
end
|
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
|
def filter_conversations
|
||||||
conversation_ids = PgSearch.multisearch("#{@params[:q]}%").where(account_id: @current_account,
|
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)
|
@conversations = Conversation.where(id: conversation_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ module MultiSearchableHelpers
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_pg_search_records
|
def contacts_pg_search_records
|
||||||
contacts_pg_search_records ||= PgSearch::Document.where(
|
PgSearch::Document.where(
|
||||||
searchable_type: 'Contact',
|
searchable_type: 'Contact',
|
||||||
searchable_id: contact_id,
|
searchable_id: contact_id,
|
||||||
account_id: account_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
|
json.channel_type conversation.inbox.channel_type
|
||||||
end
|
end
|
||||||
json.messages do
|
json.messages do
|
||||||
json.array! conversation.messages.last(1) do |message|
|
json.array! conversation.messages do |message|
|
||||||
json.content message.content
|
json.content message.content
|
||||||
json.id message.id
|
json.id message.id
|
||||||
json.sender_name message.sender.name if message.sender
|
json.sender_name message.sender.name if message.sender
|
||||||
|
|
|
@ -71,6 +71,7 @@ Rails.application.routes.draw do
|
||||||
get :meta
|
get :meta
|
||||||
get :search
|
get :search
|
||||||
post :filter
|
post :filter
|
||||||
|
get :text_search
|
||||||
end
|
end
|
||||||
scope module: :conversations do
|
scope module: :conversations do
|
||||||
resources :messages, only: [:index, :create, :destroy]
|
resources :messages, only: [:index, :create, :destroy]
|
||||||
|
|
Loading…
Reference in a new issue