Add complete Biblical Guide web application with Material UI
Implemented comprehensive Romanian Biblical Guide web app: - Next.js 15 with App Router and TypeScript - Material UI 7.3.2 for modern, responsive design - PostgreSQL database with Prisma ORM - Complete Bible reader with book/chapter navigation - AI-powered biblical chat with Romanian responses - Prayer wall for community prayer requests - Advanced Bible search with filters and highlighting - Sample Bible data imported from API.Bible - All API endpoints created and working - Professional Material UI components throughout - Responsive layout with navigation and theme 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
171
app/api/search/verses/route.ts
Normal file
171
app/api/search/verses/route.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
const testament = searchParams.get('testament') || 'all'
|
||||
const exactMatch = searchParams.get('exactMatch') === 'true'
|
||||
const books = searchParams.get('books')?.split(',').filter(Boolean) || []
|
||||
|
||||
if (!query) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Query parameter is required',
|
||||
results: []
|
||||
},
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// Build search conditions
|
||||
const searchConditions: any = {}
|
||||
|
||||
// Text search conditions
|
||||
if (exactMatch) {
|
||||
searchConditions.text = {
|
||||
contains: query,
|
||||
mode: 'insensitive'
|
||||
}
|
||||
} else {
|
||||
// Use ilike for partial matching
|
||||
searchConditions.text = {
|
||||
contains: query,
|
||||
mode: 'insensitive'
|
||||
}
|
||||
}
|
||||
|
||||
// Testament filter
|
||||
let testamentFilter = {}
|
||||
if (testament === 'old') {
|
||||
// Old Testament books (approximate book IDs 1-39)
|
||||
testamentFilter = {
|
||||
chapter: {
|
||||
book: {
|
||||
orderNum: {
|
||||
lte: 39
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (testament === 'new') {
|
||||
// New Testament books (approximate book IDs 40+)
|
||||
testamentFilter = {
|
||||
chapter: {
|
||||
book: {
|
||||
orderNum: {
|
||||
gt: 39
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Books filter
|
||||
let booksFilter = {}
|
||||
if (books.length > 0) {
|
||||
booksFilter = {
|
||||
chapter: {
|
||||
book: {
|
||||
name: {
|
||||
in: books
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combine all filters
|
||||
const whereCondition = {
|
||||
...searchConditions,
|
||||
...testamentFilter,
|
||||
...booksFilter
|
||||
}
|
||||
|
||||
// Search verses
|
||||
const verses = await prisma.bibleVerse.findMany({
|
||||
where: whereCondition,
|
||||
include: {
|
||||
chapter: {
|
||||
include: {
|
||||
book: true
|
||||
}
|
||||
}
|
||||
},
|
||||
take: 50, // Limit results
|
||||
orderBy: [
|
||||
{
|
||||
chapter: {
|
||||
book: {
|
||||
orderNum: 'asc'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
chapter: {
|
||||
chapterNum: 'asc'
|
||||
}
|
||||
},
|
||||
{
|
||||
verseNum: 'asc'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// Transform results to match expected format
|
||||
const results = verses.map(verse => {
|
||||
// Calculate relevance based on how well the search term matches
|
||||
const lowerText = verse.text.toLowerCase()
|
||||
const lowerQuery = query.toLowerCase()
|
||||
|
||||
let relevance = 0.5 // Base relevance
|
||||
|
||||
if (exactMatch && lowerText.includes(lowerQuery)) {
|
||||
relevance = 0.95
|
||||
} else if (lowerText.includes(lowerQuery)) {
|
||||
relevance = 0.8
|
||||
} else {
|
||||
// Check for word matches
|
||||
const queryWords = lowerQuery.split(/\s+/)
|
||||
const textWords = lowerText.split(/\s+/)
|
||||
const matchingWords = queryWords.filter(word =>
|
||||
textWords.some(textWord => textWord.includes(word))
|
||||
)
|
||||
relevance = 0.3 + (matchingWords.length / queryWords.length) * 0.4
|
||||
}
|
||||
|
||||
return {
|
||||
id: verse.id.toString(),
|
||||
book: verse.chapter.book.name,
|
||||
chapter: verse.chapter.chapterNum,
|
||||
verse: verse.verseNum,
|
||||
text: verse.text,
|
||||
relevance: Math.min(relevance, 1.0) // Cap at 1.0
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
results,
|
||||
total: results.length,
|
||||
query,
|
||||
filters: {
|
||||
testament,
|
||||
exactMatch,
|
||||
books
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error searching verses:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Failed to search verses',
|
||||
results: []
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user