درخواست ها
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
export default {
|
||||
base: {
|
||||
get_document: "elp/v1/indices/{{type_name}}/{{doc_id}}",
|
||||
update_document: "elp/v1/indices/{{type_name}}/update/{{doc_id}}",
|
||||
update_field: "elp/v1/indices/{{type_name}}/update/field/{{doc_id}}",
|
||||
compute_field: "elp/v1/indices/{{type_name}}/compute/field",
|
||||
add_document: "elp/v1/indices/{{type_name}}/insert",
|
||||
delete_document: "elp/v1/indices/{{type_name}}/delete/{{doc_id}}",
|
||||
getSchema: "elp/schema/get",
|
||||
},
|
||||
search: {
|
||||
elp_base_count: "elp/v1/indices/{{index_key}}/count",
|
||||
elp_base_search: "elp/v1/indices/{{index_key}}/search",
|
||||
elp_voice_search: "elp/voice/{{index_key}}/search",
|
||||
elp_db_search: "elp/db/indices/{{index_key}}/search",
|
||||
},
|
||||
Info: {
|
||||
elp_option_get: "elp/v1/base/option/doc/{{main_key}}",
|
||||
elp_completion: "elp/v1/indices/{{type_name}}/completion/{{property_key}}",
|
||||
elp_main_label: "elp/v1/base/option/get/items/{{main_label}}",
|
||||
elp_update_field: "elp/v1/indices/{{type_name}}/update/field/{{doc_id}}",
|
||||
elp_list_Tree: "/elp/tbase/{{type_name}}/list/tree",
|
||||
elp_get_Tree: "/elp/tbase/{{type_name}}/get/item/all",
|
||||
elp_update_Tree: "/elp/tbase/{{type_name}}/update/{{id}}",
|
||||
elp_delete_Tree: "/elp/tbase/{{type_name}}/delete/{{id}}",
|
||||
elp_move_in_Tree:
|
||||
"/elp/tbase/{{type_name}}/move_in/{{drop_id}}/{{drag_id}}",
|
||||
elp_insert_Tree: "/elp/tbase/{{type_name}}/insert",
|
||||
elp_relation_Tree: "/elp/tbase/{{type_name}}/relation/add",
|
||||
elp_relation_Tree_delete: "/elp/tbase/{{type_name}}/relation/delete",
|
||||
elp_get_list_Tree: "/elp/db/indices/{{index_key}}/tree",
|
||||
},
|
||||
rag_chat: {
|
||||
// elp_semantic_search: "elp/chat/semantic_search",
|
||||
elp_chat: "elp/chat/query/{{type_name}}",
|
||||
note_action: "elp/note/ai/action",
|
||||
note_job_action: "elp/chat/job/add/action/{{note_id}}",
|
||||
chat_job_query: "elp/chat/job/add/query/{{type_name}}/{{note_id}}",
|
||||
chat_job_search_query: "elp/chat/job/search/query/{{type_name}}",
|
||||
chat_job_get: "elp/chat/job/get/{{job_id}}",
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
export default {
|
||||
search: {
|
||||
mirror_search:
|
||||
"repo/monir/mirror/{{mirror_type}}/{{index_key}}/{{search_type}}/{{sortKey}}/{{field_collapse}}/{{offset}}/{{limit}}/{{filter}}",
|
||||
autoComplate: "monir/complation/{{index_key}}/{{filter}}",
|
||||
queryNormal:
|
||||
"repo/monir/search/{{index_key}}/{{search_type}}/{{sortKey}}/{{field_collapse}}/{{offset}}/{{limit}}/{{filter}}",
|
||||
textSearch:
|
||||
"repo/monir/search/text/{{index_key}}/{{field}}/{{offset}}/{{limit}}/{{filter}}",
|
||||
// queryMirror:
|
||||
// "monir/mirror/{{mirror_type}}/{{index_key}}/{{search_type}}/{{sortKey}}/{{field_collapse}}/{{offset}}/{{limit}}/{{filter}}",
|
||||
},
|
||||
|
||||
public: {
|
||||
updateProperty_full:
|
||||
"public/{{index_key}}/edit/{{entity_id}}/{{property}}/index/full",
|
||||
|
||||
updateEntity: "repo/public/{{index_key}}/update/{{id}}",
|
||||
get_doc_byid: "repo/public/get/byid/{{index_key}}/{{entity_id}}",
|
||||
uplaod_file: "repo/public/file/{{type_key}}/uploadfile",
|
||||
},
|
||||
calendar: {
|
||||
schema: {
|
||||
list: "repo/schema",
|
||||
},
|
||||
list: "repo/calendar/@offset/@limit/@filter",
|
||||
list_collpase: "repo/calendar/@field_collapsed/@offset/@limit/@filter",
|
||||
addTask: "repo/calendar/add",
|
||||
update: "repo/calendar/edit/@id",
|
||||
delete: "repo/calendar/delete/@id",
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,977 @@
|
||||
// @/composables/useFormBuilder.js
|
||||
import { useNuxtApp } from "#app";
|
||||
import elpApi from "@/apis/elpApi";
|
||||
import repoApi from "@/apis/repoApi";
|
||||
import { cleanTextUnpermittedChars } from "@/utils/generalUtil";
|
||||
|
||||
export function useElpService(props, emit) {
|
||||
const { $http: httpService } = useNuxtApp();
|
||||
const toast = useToast();
|
||||
|
||||
///-----------------------------------------------------
|
||||
///---- اسکیمای صفحات برنامه
|
||||
///-----------------------------------------------------
|
||||
async function uepGetSchema(system = "search", organ = "monir") {
|
||||
let payload = {
|
||||
organ: organ,
|
||||
system: system,
|
||||
};
|
||||
|
||||
const url = elpApi.base.getSchema;
|
||||
|
||||
return await httpService
|
||||
.postRequest(url, payload)
|
||||
.then((res) => {
|
||||
return res?.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: err?.message,
|
||||
color: "red",
|
||||
});
|
||||
return {};
|
||||
});
|
||||
|
||||
dataEntrySchema.value = res?.data || {};
|
||||
}
|
||||
|
||||
///-----------------------------------------------------
|
||||
///--- گرفتن اطلاعات سند (GET Document)
|
||||
///-----------------------------------------------------
|
||||
async function uepGetDocument(entityId, key = "") {
|
||||
if (!entityId) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "شناسه وجود ندارد",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.get_document;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
url = url.replace("{{doc_id}}", entityId);
|
||||
|
||||
return await httpService
|
||||
.getRequest(url)
|
||||
.then((res) => {
|
||||
return res; // معمولاً شامل doc_id یا کل سند ایجاد شده است
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error in 1 :", error);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در گرفتن سند، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
async function myPostRequest(
|
||||
url,
|
||||
payload,
|
||||
by_message = false,
|
||||
message = "عملیات با موفقیت انجام شد"
|
||||
) {
|
||||
try {
|
||||
const res = await httpService.postRequest(url, payload);
|
||||
|
||||
if (by_message && toast?.add) {
|
||||
toast.add({
|
||||
title: "موفق",
|
||||
description: message,
|
||||
icon: "i-lucide-file-plus",
|
||||
});
|
||||
}
|
||||
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error("Error in myPostRequest:", error);
|
||||
|
||||
if (toast?.add) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در عملیات، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
///-----------------------------------------------------
|
||||
///--- ایجاد سند جدید (Add Document)
|
||||
///-- payload = {
|
||||
///-- id: "" -- اختیاری
|
||||
///-- docuemnt : {
|
||||
///-- title: "..."
|
||||
///-- ...
|
||||
///-- sections: [ ... ]
|
||||
///-- ...
|
||||
///-- }
|
||||
///-- }
|
||||
|
||||
///-----------------------------------------------------
|
||||
async function uepAddDocument(payload, key = "", by_message = false) {
|
||||
if (!payload) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "دادههای سند برای ایجاد الزامی است",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let doc = {
|
||||
document: { ...payload },
|
||||
};
|
||||
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.add_document;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
|
||||
return await httpService
|
||||
.postRequest(url, doc)
|
||||
.then((res) => {
|
||||
if (by_message)
|
||||
toast.add({
|
||||
title: "موفق",
|
||||
description: "سند جدید با موفقیت ایجاد شد.",
|
||||
icon: "i-lucide-file-plus",
|
||||
});
|
||||
return res; // معمولاً شامل doc_id یا کل سند ایجاد شده است
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error in 1 :", error);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در ایجاد سند جدید، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
async function uepInsertTree(payload, typeName = "gntree") {
|
||||
if (!payload) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "اطلاعات گره برای ایجاد الزامی است",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const url = elpApi.Info.elp_insert_Tree.replace("{{type_name}}", typeName);
|
||||
|
||||
return await httpService.postRequest(url, payload).catch((error) => {
|
||||
console.error("ساخت گرهٔ درخت ناموفق بود:", error);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در ایجاد گرهٔ درخت، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
async function uepGetTree(payload, typeName = "gntree") {
|
||||
const url = elpApi.Info.elp_get_Tree.replace("{{type_name}}", typeName);
|
||||
|
||||
return await httpService.postRequest(url, payload).catch((error) => {
|
||||
console.error("خواندن درخت ناموفق بود:", error);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
async function uepDeleteTree(nodeId, typeName = "gntree") {
|
||||
const url = elpApi.Info.elp_delete_Tree
|
||||
.replace("{{type_name}}", typeName)
|
||||
.replace("{{id}}", nodeId);
|
||||
|
||||
return await httpService.postRequest(url).catch((error) => {
|
||||
console.error("حذف گرهٔ درخت ناموفق بود:", error);
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
async function uepUpdateTree(nodeId, payload, typeName = "gntree") {
|
||||
if (!nodeId) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "شناسه گره برای ویرایش الزامی است",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!payload) {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "اطلاعات گره برای ویرایش الزامی است",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const url = elpApi.Info.elp_update_Tree
|
||||
.replace("{{type_name}}", typeName)
|
||||
.replace("{{id}}", nodeId);
|
||||
|
||||
try {
|
||||
return await httpService.postRequest(url, payload);
|
||||
} catch (error) {
|
||||
console.error("ویرایش گره درخت ناموفق بود:", error);
|
||||
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در ویرایش گره، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
///-----------------------------------------------------
|
||||
///--- آپدیت کامل داکیومنت (چند فیلد باهم)
|
||||
///-- payload = {
|
||||
///-- document : {
|
||||
///-- title: "..."
|
||||
///-- ...
|
||||
///-- sections: [ ... ]
|
||||
///-- ...
|
||||
///-- }
|
||||
///-- }
|
||||
///-----------------------------------------------------
|
||||
async function uepUpdateDocument(
|
||||
doc_id,
|
||||
payload,
|
||||
key = "",
|
||||
by_message = false
|
||||
) {
|
||||
if (!doc_id) return;
|
||||
|
||||
let doc = {
|
||||
id: doc_id,
|
||||
document: { ...payload },
|
||||
};
|
||||
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.update_document; // باید این route در بک وجود داشته باشد
|
||||
url = url.replace("{{type_name}}", key);
|
||||
url = url.replace("{{doc_id}}", doc_id);
|
||||
|
||||
return await httpService
|
||||
.postRequest(url, doc)
|
||||
.then((res) => {
|
||||
if (by_message)
|
||||
toast.add({
|
||||
title: "موفق",
|
||||
description: "سند با موفقیت بروزرسانی شد.",
|
||||
icon: "i-lucide-check",
|
||||
});
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error in 2 :", err);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در بروزرسانی سند " + err.message,
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
///-----------------------------------------------------
|
||||
///--- یک فیلد را بروزرسانی می کند
|
||||
///-- payload = {
|
||||
///-- field_key: str
|
||||
///-- field_value: Any
|
||||
///-- action: str = 'edit' # edit, add, delete, full
|
||||
///-- index_in_array: Optional[int] = None
|
||||
///-- id_in_array: Optional[str] = None
|
||||
///-- }
|
||||
///-----------------------------------------------------
|
||||
async function uepUpdateField(doc_id, payload, key = "", by_message = false) {
|
||||
if (!doc_id) {
|
||||
alert("شناسه uepUpdateField !!");
|
||||
return undefined;
|
||||
}
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.update_field;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
url = url.replace("{{doc_id}}", doc_id);
|
||||
return await httpService
|
||||
.postRequest(url, payload)
|
||||
.then(() => {
|
||||
if (by_message)
|
||||
toast.add({
|
||||
title: "موفق",
|
||||
description: "عملیات با موفقیت انجام شد.",
|
||||
icon: "i-lucide-calendar-days",
|
||||
});
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error in 3 :", err);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در انجام دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
///-----------------------------------------------------
|
||||
///- حذف کامل یک سند با شناسه مشخص
|
||||
///-----------------------------------------------------
|
||||
async function uepDeleteDocument(doc_id, key = "", by_message = false) {
|
||||
if (!doc_id) return;
|
||||
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.delete_document;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
url = url.replace("{{doc_id}}", doc_id);
|
||||
return await httpService
|
||||
.postRequest(url, {})
|
||||
.then(() => {
|
||||
if (by_message)
|
||||
toast.add({
|
||||
title: "موفق",
|
||||
description: "عملیات با موفقیت انجام شد.",
|
||||
icon: "i-lucide-calendar-days",
|
||||
});
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error in 7 :", err);
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در انجام دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
///-----------------------------------------------------
|
||||
///--- با توجه به یک فیلد، مقدار محاسبه شده ای بر میگردند مثلا : بیشترین مقدار یا مجموع یا ...
|
||||
///-----------------------------------------------------
|
||||
async function uepGetComputeField(
|
||||
key = "",
|
||||
property_key = "meet_no",
|
||||
compute_key = "max",
|
||||
filters = {}
|
||||
) {
|
||||
let payload = {
|
||||
compute_key,
|
||||
property_key,
|
||||
filters,
|
||||
};
|
||||
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let url = elpApi.base.compute_field;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
|
||||
return await httpService
|
||||
.postRequest(url, payload)
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch(() => {
|
||||
toast.add({
|
||||
title: "خطا",
|
||||
description: "خطا در انجام عملیات، دوباره تلاش کنید",
|
||||
color: "red",
|
||||
});
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
//-------------------------------------------
|
||||
async function createSearchRequest(
|
||||
index_key,
|
||||
textSearch,
|
||||
searchTypeKey,
|
||||
mode_url = "normal",
|
||||
filterPanel = "",
|
||||
filterExtended = "",
|
||||
offset = 0,
|
||||
limit = 10,
|
||||
field_collapse = "normal",
|
||||
sortKey = "normal",
|
||||
domainKey = "all",
|
||||
domainSchema = {},
|
||||
user_synonyms = {},
|
||||
mirror_type = ""
|
||||
) {
|
||||
let _payload = {};
|
||||
let domain_label = "";
|
||||
let query_string = cleanTextUnpermittedChars(textSearch);
|
||||
|
||||
/* ===== Base URL ===== */
|
||||
if (!index_key) {
|
||||
const config = useRuntimeConfig();
|
||||
index_key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let baseUrl = "";
|
||||
if (mode_url === "count") {
|
||||
baseUrl = elpApi.search.elp_base_count;
|
||||
baseUrl = baseUrl.replace("{{index_key}}", index_key);
|
||||
}
|
||||
if (mode_url === "elp_db") {
|
||||
baseUrl = elpApi.search.elp_db_search;
|
||||
baseUrl = baseUrl.replace("{{index_key}}", index_key);
|
||||
} else if (mode_url === "elp_voice") {
|
||||
baseUrl = elpApi.search.elp_voice_search;
|
||||
baseUrl = baseUrl.replace("{{index_key}}", index_key);
|
||||
} else if (mode_url === "mirror") {
|
||||
baseUrl = repoApi.search.mirror_search;
|
||||
baseUrl = baseUrl.replace("{{mirror_type}}", mirror_type);
|
||||
} else if (mode_url === "elp_tree") {
|
||||
baseUrl = elpApi.Info.elp_get_list_Tree;
|
||||
baseUrl = baseUrl.replace("{{index_key}}", index_key);
|
||||
} // if (mode_url === "elp" || mode_url == "")
|
||||
else {
|
||||
baseUrl = elpApi.search.elp_base_search;
|
||||
baseUrl = baseUrl.replace("{{index_key}}", index_key);
|
||||
}
|
||||
|
||||
// ====Synonym / Vector / Normal
|
||||
let sysnonymSearchQuery = "";
|
||||
|
||||
if (!searchTypeKey) searchTypeKey = "normal";
|
||||
|
||||
if (searchTypeKey === "synonym") {
|
||||
let newSynonym = {};
|
||||
|
||||
if (user_synonyms) {
|
||||
Object.keys(user_synonyms).forEach((key) => {
|
||||
if (
|
||||
!(
|
||||
"isStopWord" in user_synonyms[key] &&
|
||||
user_synonyms[key].isStopWord
|
||||
)
|
||||
) {
|
||||
newSynonym[key] = user_synonyms[key].value;
|
||||
sysnonymSearchQuery += " " + key;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (textSearch === "" || textSearch === undefined)
|
||||
textSearch = sysnonymSearchQuery;
|
||||
|
||||
if (Object.keys(newSynonym).length) {
|
||||
_payload = {
|
||||
synonym: newSynonym,
|
||||
};
|
||||
}
|
||||
} else if (searchTypeKey === "vector") {
|
||||
/* ===== Vector ===== */
|
||||
_payload = {
|
||||
text: query_string,
|
||||
};
|
||||
} else if (!(textSearch === "" || textSearch === undefined)) {
|
||||
/* ===== Normal ===== */
|
||||
query_string = query_string;
|
||||
|
||||
if (!domainKey) domainKey = "all";
|
||||
|
||||
if (domainKey === "all") {
|
||||
if (domainSchema?.type_action) {
|
||||
let isNumberInput = /^\d+$/.test(query_string);
|
||||
|
||||
if (isNumberInput && domainSchema.type_action.number) {
|
||||
let tag = domainSchema.type_action.number;
|
||||
query_string = encodeURIComponent("#") + tag + " " + query_string;
|
||||
}
|
||||
}
|
||||
} else if (domainKey !== "advance") {
|
||||
let domainItem = domainSchema?.domain?.find(
|
||||
(item) => item.key === domainKey
|
||||
);
|
||||
|
||||
if (domainItem) {
|
||||
domain_label = domainItem.label;
|
||||
query_string =
|
||||
encodeURIComponent("#") + domainItem.tag + " " + query_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Filters
|
||||
let filterFull = "";
|
||||
|
||||
if (searchTypeKey !== "vector" && query_string) {
|
||||
filterFull += "q=" + query_string;
|
||||
}
|
||||
|
||||
filterFull += filterPanel + filterExtended;
|
||||
|
||||
if (!filterFull) filterFull = "none";
|
||||
|
||||
// ==== URL Replace
|
||||
let url = baseUrl;
|
||||
const buildName = import.meta.env.VITE_BUILD_NAME;
|
||||
|
||||
url = url.replace("{{appname}}", buildName);
|
||||
url = url.replace("{{index_key}}", index_key);
|
||||
url = url.replace("{{search_type}}", searchTypeKey);
|
||||
url = url.replace("{{sortKey}}", sortKey);
|
||||
url = url.replace("{{field_collapse}}", field_collapse);
|
||||
url = url.replace("{{offset}}", offset);
|
||||
url = url.replace("{{limit}}", limit);
|
||||
url = url.replace("{{filter}}", filterFull);
|
||||
|
||||
// == Payload
|
||||
let filters = (filterPanel + filterExtended)
|
||||
.split("&")
|
||||
.filter((e) => e.length);
|
||||
|
||||
let filters_obj = {};
|
||||
filters.forEach((fl) => {
|
||||
let fl_items = fl.split("=");
|
||||
if (fl_items.length === 2) filters_obj[fl_items[0]] = fl_items[1];
|
||||
});
|
||||
|
||||
let payload_full = {
|
||||
track_total_hits: true,
|
||||
query: query_string,
|
||||
search_type: searchTypeKey,
|
||||
filters: filters_obj,
|
||||
sort: [sortKey],
|
||||
from_: offset,
|
||||
size: limit,
|
||||
collapse_field: field_collapse,
|
||||
};
|
||||
|
||||
if (_payload.synonym) {
|
||||
payload_full.user_synonyms = _payload.synonym;
|
||||
}
|
||||
|
||||
return {
|
||||
url,
|
||||
payload_full,
|
||||
payload: _payload,
|
||||
sysnonymSearchQuery,
|
||||
domainLabel: domain_label,
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
async function uepGetDataSearch({
|
||||
index_key,
|
||||
textSearch,
|
||||
searchTypeKey,
|
||||
mode_url,
|
||||
filterPanel,
|
||||
filterExtended,
|
||||
filterids,
|
||||
offset,
|
||||
limit,
|
||||
field_collapse,
|
||||
sortKey,
|
||||
domainKey,
|
||||
domainSchema,
|
||||
user_synonyms,
|
||||
mirror_type,
|
||||
synonymData,
|
||||
aggregations,
|
||||
}) {
|
||||
if (!index_key) {
|
||||
const config = useRuntimeConfig();
|
||||
index_key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
const request = await createSearchRequest(
|
||||
index_key,
|
||||
textSearch ?? "",
|
||||
searchTypeKey ?? "normal",
|
||||
mode_url ?? "elp",
|
||||
filterPanel ?? "",
|
||||
filterExtended ?? "",
|
||||
offset ?? 0,
|
||||
limit ?? 10,
|
||||
field_collapse ?? "normal",
|
||||
sortKey ?? "normal",
|
||||
domainKey ?? "all",
|
||||
domainSchema ?? {},
|
||||
user_synonyms ?? {},
|
||||
mirror_type ?? ""
|
||||
);
|
||||
|
||||
let payload_full = request.payload_full;
|
||||
if (filterids?.length) {
|
||||
if (!"filters" in payload_full) payload_full["filters"] = {};
|
||||
payload_full.filters["ids"] = filterids;
|
||||
}
|
||||
|
||||
//------------------
|
||||
if (aggregations && Object.keys(aggregations).length) {
|
||||
request.payload_full.aggregation_fields = aggregations;
|
||||
}
|
||||
//------------------
|
||||
if (synonymData && Object.keys(synonymData).length) {
|
||||
if (synonymData.synonyms?.length > 0) {
|
||||
request.payload_full.synonyms = synonymData.synonyms;
|
||||
}
|
||||
if (Object.keys(synonymData.user_synonyms)?.length) {
|
||||
request.payload_full.user_synonyms = synonymData.user_synonyms;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(request.url, payload_full);
|
||||
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return {};
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
async function uepLogSearchQuery(query) {
|
||||
let key = "logsearch";
|
||||
|
||||
let doc = {
|
||||
query,
|
||||
};
|
||||
|
||||
let url = elpApi.base.add_document;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
return await myPostRequest(url, doc, by_message);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
//-------------------------------------------
|
||||
|
||||
// جستجوی معنایی از مسیر کارهای چت (chat job)
|
||||
/*
|
||||
offset و limit برای صفحهبندی است (مثل بقیهٔ متدهای جستجو)؛
|
||||
در پیلود با نامهای from_ و size فرستاده میشوند که فیلدهای سرورند.
|
||||
*/
|
||||
async function uepChatJobSearchQuery(
|
||||
query,
|
||||
key,
|
||||
filters = [],
|
||||
offset = 0,
|
||||
limit = 10,
|
||||
lexical_weight = 0.5,
|
||||
vector_weight = 0.5,
|
||||
vector_reranker = false
|
||||
) {
|
||||
|
||||
|
||||
const url = elpApi.rag_chat.chat_job_search_query.replace(
|
||||
"{{type_name}}",
|
||||
key
|
||||
);
|
||||
|
||||
let filters_obj = {};
|
||||
filters.forEach((el) => {
|
||||
let fls = el.split("&");
|
||||
fls.forEach((fl) => {
|
||||
let fl_items = fl.split("=");
|
||||
if (fl_items.length === 2) filters_obj[fl_items[0]] = fl_items[1];
|
||||
});
|
||||
});
|
||||
|
||||
const payload = {
|
||||
query: query ?? "",
|
||||
from_: offset,
|
||||
size: limit,
|
||||
lexical_weight,
|
||||
vector_weight,
|
||||
vector_reranker,
|
||||
filters: filters_obj,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(url, payload);
|
||||
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error("uepChatJobSearchQuery error:", err);
|
||||
return {};
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
async function uepChatRag(query, key, filters = [], is_rerank = false) {
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
let filters_obj = {};
|
||||
filters.forEach((fl) => {
|
||||
let fl_items = fl.split("=");
|
||||
if (fl_items.length === 2) filters_obj[fl_items[0]] = fl_items[1];
|
||||
});
|
||||
|
||||
let payload = {
|
||||
query,
|
||||
filters: filters_obj,
|
||||
sort: ["normal"],
|
||||
size: 100,
|
||||
is_rerank,
|
||||
rerank_limit: 10,
|
||||
};
|
||||
|
||||
let url = elpApi.rag_chat.elp_chat;
|
||||
url = url.replace("{{type_name}}", key);
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(
|
||||
url,
|
||||
payload,
|
||||
{ timeout: 180000 } // سه دقیقه
|
||||
);
|
||||
|
||||
if (res.status == "success") return res.result;
|
||||
else return res;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return {};
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
async function uepCahtLLM(user_prompt) {
|
||||
let payload = {
|
||||
user_prompt,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(
|
||||
elpApi.rag_chat.note_action,
|
||||
payload
|
||||
);
|
||||
|
||||
if (res.status == "success") return res.result;
|
||||
else return res;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return {};
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
async function uepJobAdd(payload, note_id, key = "", onProgress) {
|
||||
if (!key) {
|
||||
const config = useRuntimeConfig();
|
||||
key = config.public.NUXT_PUBLIC_INDEX_KEY;
|
||||
}
|
||||
|
||||
const url = elpApi.rag_chat.chat_job_query
|
||||
.replace("{{type_name}}", key)
|
||||
.replace("{{note_id}}", note_id);
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(url, payload);
|
||||
// console.log("add res ==> ", res);
|
||||
|
||||
if (!res?.id) return res;
|
||||
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error("uepJobAdd error:", err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
async function uepJobGet(job_id) {
|
||||
if (!job_id) return { job_status: "error", result: {} };
|
||||
|
||||
const url = elpApi.rag_chat.chat_job_get.replace("{{job_id}}", job_id);
|
||||
|
||||
try {
|
||||
const res = await httpService.getRequest(url);
|
||||
// console.log("get res ==> ", res);
|
||||
|
||||
const body = res?.result ?? res ?? {};
|
||||
|
||||
return {
|
||||
...body,
|
||||
result: body,
|
||||
job_status: body.job_status ?? res?.job_status ?? "wait",
|
||||
};
|
||||
} catch (err) {
|
||||
console.error("uepJobGet error:", err);
|
||||
|
||||
return { job_status: "wait", result: {}, has_error: true };
|
||||
}
|
||||
}
|
||||
async function uepJobWaitForFinish(job_id, onProgress, options = {}) {
|
||||
const repeatTimeQuery = 5000;
|
||||
const maxRetryOnError = 5;
|
||||
const abortSignal = options.signal;
|
||||
|
||||
/*
|
||||
اگر کاربر «توقف» را بزند، حلقه فوراً و بدون درخواست بعدی خارج میشود.
|
||||
*/
|
||||
function throwIfStopped() {
|
||||
if (!abortSignal?.aborted) return;
|
||||
|
||||
const abortError = new Error("پاسخ متوقف شد");
|
||||
abortError.name = "AbortError";
|
||||
throw abortError;
|
||||
}
|
||||
|
||||
/* انتظار بین دو درخواست، با قابلیت قطع فوری */
|
||||
function waitForNextPoll() {
|
||||
return new Promise((resolve) => {
|
||||
if (!abortSignal) {
|
||||
setTimeout(resolve, repeatTimeQuery);
|
||||
return;
|
||||
}
|
||||
|
||||
const timeoutId = setTimeout(() => {
|
||||
abortSignal.removeEventListener("abort", handleAbort);
|
||||
resolve();
|
||||
}, repeatTimeQuery);
|
||||
|
||||
function handleAbort() {
|
||||
clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
|
||||
abortSignal.addEventListener("abort", handleAbort, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
let retry = 0;
|
||||
|
||||
while (true) {
|
||||
throwIfStopped();
|
||||
|
||||
const res = await uepJobGet(job_id);
|
||||
|
||||
throwIfStopped();
|
||||
|
||||
const result = res.result ?? {};
|
||||
const status = res.job_status;
|
||||
|
||||
if (res.has_error) {
|
||||
retry += 1;
|
||||
|
||||
if (retry > maxRetryOnError) {
|
||||
throw new Error(`Job unreachable after ${retry} tries: ${job_id}`);
|
||||
}
|
||||
|
||||
await waitForNextPoll();
|
||||
continue;
|
||||
}
|
||||
|
||||
retry = 0;
|
||||
|
||||
if (typeof onProgress === "function") {
|
||||
try {
|
||||
onProgress(result, { job_status: status });
|
||||
} catch (err) {
|
||||
console.error("onProgress error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
if (status === "finish") {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (status === "error" || status === "cancel") {
|
||||
throw new Error(`Job ${status}: ${job_id}`);
|
||||
}
|
||||
|
||||
await waitForNextPoll();
|
||||
}
|
||||
}
|
||||
async function uepJobAction(note_id, payload) {
|
||||
// console.log("note_id, payload ==> ", note_id, payload);
|
||||
if (!note_id) return {};
|
||||
|
||||
const url = elpApi.rag_chat.note_job_action.replace("{{note_id}}", note_id);
|
||||
|
||||
try {
|
||||
const res = await httpService.postRequest(url, payload);
|
||||
// console.log("action res ==> ", res);
|
||||
|
||||
if (res?.status === "success") return res.result;
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error("uepJobAction error:", err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
// ========== دریافت مترادف از سرور ==========
|
||||
const getSynonymsFromServer = async (word) => {
|
||||
try {
|
||||
let payload = {
|
||||
query: word,
|
||||
};
|
||||
|
||||
const response = await httpService.postRequest(
|
||||
elpApi.search.repo_synonym_words,
|
||||
payload
|
||||
);
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
///-----------------------------------------------------
|
||||
///-----------------------------------------------------
|
||||
return {
|
||||
uepGetDocument,
|
||||
uepAddDocument,
|
||||
uepInsertTree,
|
||||
uepGetTree,
|
||||
uepDeleteTree,
|
||||
uepUpdateDocument,
|
||||
uepDeleteDocument,
|
||||
uepGetDataSearch,
|
||||
uepChatJobSearchQuery,
|
||||
uepChatRag,
|
||||
uepCahtLLM,
|
||||
getSynonymsFromServer,
|
||||
uepUpdateField,
|
||||
uepJobAdd,
|
||||
uepJobGet,
|
||||
uepJobWaitForFinish,
|
||||
uepGetSchema,
|
||||
uepGetComputeField,
|
||||
uepJobAction,
|
||||
uepUpdateTree,
|
||||
};
|
||||
}
|
||||
|
||||
export default useElpService;
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -19,7 +19,7 @@ export default defineNuxtConfig({
|
||||
css: ["~/assets/css/main.css"],
|
||||
|
||||
imports: {
|
||||
dirs: ["stores", "composables", "apis"],
|
||||
dirs: ["stores", "composables", "apis", "utils"],
|
||||
},
|
||||
|
||||
colorMode: {
|
||||
|
||||
Reference in New Issue
Block a user