Skip to content

Latest commit

 

History

History
57 lines (50 loc) · 1.61 KB

prismaFetch.mdx

File metadata and controls

57 lines (50 loc) · 1.61 KB

{/* SEARCH QUERY */}

// Import Prisma client
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

// Search function
async function search(query: string) {
  const results = await Promise.all([
    prisma.service.findMany({
      where: {
        OR: [
          { title: { contains: query, mode: 'insensitive' } },
          { slug: { contains: query, mode: 'insensitive' } },
        ],
      },
    }),
    prisma.symptom.findMany({
      where: {
        OR: [
          { title: { contains: query, mode: 'insensitive' } },
          { slug: { contains: query, mode: 'insensitive' } },
        ],
      },
    }),
    prisma.doctorProfile.findMany({
      where: {
        OR: [
          { firstName: { contains: query, mode: 'insensitive' } },
          { lastName: { contains: query, mode: 'insensitive' } },
          { middleName: { contains: query, mode: 'insensitive' } },
          { bio: { contains: query, mode: 'insensitive' } },
          { medicalLicense: { contains: query, mode: 'insensitive' } },
          { primarySpecialization: { contains: query, mode: 'insensitive' } },
          { otherSpecialties: { hasSome: [query] } },
          { boardCertificates: { hasSome: [query] } },
          { servicesOffered: { hasSome: [query] } },
          { educationHistory: { contains: query, mode: 'insensitive' } },
          { research: { contains: query, mode: 'insensitive' } },
          { accomplishments: { contains: query, mode: 'insensitive' } },
        ],
      },
    }),
  ]);

  return {
    services: results[0],
    symptoms: results[1],
    doctorProfiles: results[2],
  };
}