32 lines
990 B
TypeScript
32 lines
990 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getPayload } from 'payload';
|
|
import config from '@payload-config';
|
|
|
|
const payload = await getPayload({ config });
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const searchParams = req.nextUrl.searchParams;
|
|
const search = searchParams.get('search');
|
|
|
|
if (!search) {
|
|
return NextResponse.json({ error: 'No documents matching search found' }, { status: 404 });
|
|
}
|
|
|
|
const response = await payload.find({
|
|
collection: 'papers',
|
|
where: {
|
|
or: [
|
|
{ title: { contains: search } },
|
|
{ issue: { contains: search } },
|
|
{ goal: { contains: search } },
|
|
{ 'technologies.description': { contains: search } },
|
|
{ 'prototype.description': { contains: search } },
|
|
{ 'authors.description': { contains: search } },
|
|
],
|
|
},
|
|
});
|
|
|
|
const docs = response.docs.map((doc) => ({ title: doc.title, year: doc.year, id: doc.id }));
|
|
return NextResponse.json({ docs });
|
|
}
|