feat: normalize doctor name query to enhance search functionality and improve URL building

This commit is contained in:
hamed
2026-07-20 12:33:22 +03:30
parent ac3a84d55d
commit a39b90c88c
2 changed files with 42 additions and 7 deletions
+37 -3
View File
@@ -10,6 +10,40 @@ import cities from "@/data/city.json";
export const numberToArStyle = (num) => num?.toLocaleString("ar-AE") || "";
// عناوین احترامی که در نام ذخیره‌شدهٔ پزشک وجود ندارند و باید پیش از جستجو حذف شوند
const NAME_HONORIFICS = [
"دکتر",
"دكتر",
"پروفسور",
"خانم",
"آقای",
"اقای",
"آقا",
"اقا",
"جناب",
"سرکار",
];
// «دکتر مهدیه» → «مهدیه» تا جستجوی نام در API نتیجه بدهد.
// اگر بعد از حذف چیزی نماند، مقدار اصلی برگردانده می‌شود.
export const normalizeDoctorNameQuery = (value) => {
if (typeof value !== "string") return value;
let result = value.trim();
let changed = true;
while (changed) {
changed = false;
for (const honorific of NAME_HONORIFICS) {
if (result === honorific || result.startsWith(`${honorific} `)) {
result = result.slice(honorific.length).trim();
changed = true;
}
}
}
return result || value.trim();
};
export const isActiveURL = (link, name) => link === name;
// نگاشت پاسخ API بلاگ (image_url/tags/created_at/body/author-object) به شکلی که
@@ -461,7 +495,7 @@ export const QueryForDoctorsReq = (newFilter) => {
if (newFilter.gender && newFilter.gender !== "هر دو")
params.gender = newFilter.gender === "مرد" ? "man" : "woman";
if (newFilter.name) params.name = newFilter.name;
if (newFilter.name) params.name = normalizeDoctorNameQuery(newFilter.name);
if (newFilter.sort) {
if (newFilter.sort === 3) params.sort = "ASC";
@@ -502,7 +536,7 @@ export const QueryForDoctorsClinicReq = (newFilter) => {
if (newFilter.gender && newFilter.gender !== "هر دو")
params.gender = newFilter.gender === "مرد" ? "man" : "woman";
if (newFilter.name) params.name = newFilter.name;
if (newFilter.name) params.name = normalizeDoctorNameQuery(newFilter.name);
if (newFilter.sort) {
if (newFilter.sort === 3) params.sort = "ASC";
@@ -571,7 +605,7 @@ export const buildDoctorParams = (searchParams) => {
// 🔹 name
if (searchParams.name) {
params.name = searchParams.name;
params.name = normalizeDoctorNameQuery(searchParams.name);
}
// 🔹 sort (3 = ASC, 4|5 = DESC)
+5 -4
View File
@@ -1,17 +1,18 @@
import specialties from "@/data/specialties.json";
import { normalizeDoctorNameQuery } from "@/helper";
export function buildSearchUrl(data = {}) {
const filters = {};
if (data.city && data.city !== "نوبت 724") filters.city = data.city;
if (data.province) filters.state = data.province;
if (data.search) {
const specialtyItem = specialties.find((item) =>
item.name.includes(data.search)
);
// عناوین احترامی («دکتر قلب» → «قلب») حذف می‌شوند تا تطبیق تخصص و نام درست کار کند
const term = normalizeDoctorNameQuery(data.search);
const specialtyItem = specialties.find((item) => item.name.includes(term));
if (specialtyItem) {
filters.specialty = specialtyItem.name;
} else {
filters.name = data.search;
filters.name = term;
}
}