diff --git a/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/down.sql b/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/down.sql new file mode 100644 index 000000000..1dfd23a52 --- /dev/null +++ b/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/down.sql @@ -0,0 +1,5 @@ +alter table "public"."job_conversations" drop constraint "job_conversations_conversationid_fkey", + add constraint "job_conversations_conversationid_fkey" + foreign key ("conversationid") + references "public"."conversations" + ("id") on update restrict on delete restrict; diff --git a/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/up.sql b/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/up.sql new file mode 100644 index 000000000..524d765ed --- /dev/null +++ b/hasura/migrations/1686335272144_set_fk_public_job_conversations_conversationid/up.sql @@ -0,0 +1,5 @@ +alter table "public"."job_conversations" drop constraint "job_conversations_conversationid_fkey", + add constraint "job_conversations_conversationid_fkey" + foreign key ("conversationid") + references "public"."conversations" + ("id") on update cascade on delete cascade; diff --git a/server/opensearch/os-handler.js b/server/opensearch/os-handler.js index 1266e6a6c..0bc72170c 100644 --- a/server/opensearch/os-handler.js +++ b/server/opensearch/os-handler.js @@ -86,6 +86,7 @@ async function OpenSearchUpdateHandler(req, res) { "v_model_yr", "v_make_desc", "v_model_desc", + "v_vin", ]); document.bodyshopid = req.body.event.data.new.shopid; break; @@ -139,7 +140,7 @@ async function OpenSearchUpdateHandler(req, res) { "exported_at", "invoice_number", "is_credit_memo", - "total" + "total", ]), ...bill.bills_by_pk, bodyshopid: bill.bills_by_pk.job.shopid, @@ -244,17 +245,54 @@ async function OpensearchSearchHandler(req, res) { bool: { must: [ { - multi_match: { - query: search, - type: "phrase_prefix", - //fields: ["*"], - // fuzziness: "5", - //prefix_length: 2, + match: { + bodyshopid: assocs.associations[0].shopid, }, }, { - match: { - bodyshopid: assocs.associations[0].shopid, + bool: { + should: [ + { + multi_match: { + query: search, + type: "cross_fields", + fields: ["*ownr_fn", "*ownr_ln"], + }, + }, + { + multi_match: { + query: search, + type: "most_fields", + fields: [ + "*v_model_yr", + "*v_make_desc^2", + "*v_model_desc^3", + ], + }, + }, + { + query_string: { + query: `*${search}*`, + + fields: [ + "*ro_number^20", + "*clm_no^14", + "*v_vin^12", + "*plate_no^12", + "*ownr_ln^10", + "transactionid^10", + "paymentnum^10", + "invoice_number^10", + "*ownr_fn^8", + "*ownr_co_nm^8", + "*ownr_ph1^8", + "*ownr_ph2^8", + "*", + ], + }, + }, + ], + minimum_should_match: 1, }, }, ],