Skip to content

Commit

Permalink
Imporve Search and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 7, 2024
1 parent 0925ea8 commit 54cc6c1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
1 change: 0 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { auth } from "../lib/auth";
import prisma from "../lib/prisma";
import { Course, CoursePlan } from "@prisma/client";
import { getPlanCookie } from "../app/actions";
import { PlanCardList } from "../components/PlanCardList";

async function getCourses() {
const courses = await prisma.course.findMany();
Expand Down
1 change: 1 addition & 0 deletions components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "@nextui-org/react";
import { tv } from "tailwind-variants";
import { generateColorFromName } from "../components/primitives";
import { ScrollShadow } from "@nextui-org/react";

import { InstructorCard } from "./InstructorCard";
import AddIcon from "@mui/icons-material/Add";
Expand Down
40 changes: 22 additions & 18 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function getCourses(
console.log(startTime);
return await prisma.course.findMany({
relationLoadStrategy: "join", // or 'query'

include: {
sectionAttributes: true,
facultyMeet: {
Expand All @@ -31,11 +30,10 @@ async function getCourses(
{
_relevance: {
fields: ["courseTitle", "subject", "courseNumber"],
search: query.replace(/[\s\n\t]/g, "_"),
search: query.trim().split(" ").join(" & "),
sort: "desc",
},
},
{},
],
where: {
...(term
Expand All @@ -45,6 +43,12 @@ async function getCourses(
: {}),
//year: term,

OR: [
{ courseTitle: { search: query.trim().split(" ").join(" & ") } },
{ subject: { search: query.trim().split(" ").join(" & ") } },
{ courseNumber: { search: query.trim().split(" ").join(" & ") } },
],

...(startTime.length > 0
? {
facultyMeet: {
Expand All @@ -57,23 +61,23 @@ async function getCourses(
}
: {}),

OR: [
{
facultyMeet: {
meetingTimes: {
is: {
monday: dotw.includes("monday") ? true : Prisma.skip,
tuesday: dotw.includes("tuesday") ? true : Prisma.skip,
wednesday: dotw.includes("wednesday") ? true : Prisma.skip,
thursday: dotw.includes("thursday") ? true : Prisma.skip,
friday: dotw.includes("friday") ? true : Prisma.skip,
saturday: dotw.includes("saturday") ? true : Prisma.skip,
sunday: dotw.includes("sunday") ? true : Prisma.skip,
...(dotw.length > 0
? {
facultyMeet: {
meetingTimes: {
is: {
monday: dotw.includes("monday") ? true : Prisma.skip,
tuesday: dotw.includes("tuesday") ? true : Prisma.skip,
wednesday: dotw.includes("wednesday") ? true : Prisma.skip,
thursday: dotw.includes("thursday") ? true : Prisma.skip,
friday: dotw.includes("friday") ? true : Prisma.skip,
saturday: dotw.includes("saturday") ? true : Prisma.skip,
sunday: dotw.includes("sunday") ? true : Prisma.skip,
},
},
},
},
},
],
}
: {}),
},
});
}
Expand Down
3 changes: 2 additions & 1 deletion components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function Search(props: any) {

useEffect(() => {
// Update the document title using the browser API
setSelectedTerm(searchParams.get("term")?.toString().split(","));
setSelectedDOTW(searchParams.get("dotw")?.toString().split(","));
setSelectedStartTime(searchParams.get("stime")?.toString().split(","));
//handleSelectionChange({ target: { value: selectedTerm } });
Expand Down Expand Up @@ -111,7 +112,7 @@ export default function Search(props: any) {

<Select
label="Select Term"
//disallowEmptySelection={true}
disallowEmptySelection={true}
className="max-w-xs col-span-1"
selectedKeys={selectedTerm}
defaultSelectedKeys={searchParams.get("term")?.toString()}
Expand Down
2 changes: 2 additions & 0 deletions prisma/migrations/20241107200105_create_indexes/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX "subj_course" ON "Course"("subject", "courseNumber");
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "relationJoins", "strictUndefinedChecks"]
previewFeatures = ["fullTextSearch", "relationJoins", "strictUndefinedChecks","fullTextIndex"]
}

datasource db {
Expand Down Expand Up @@ -46,6 +46,7 @@ model Course {
sectionAttributes sectionAttribute[]
CoursePlan CoursePlan[]
year String
@@index([subject, courseNumber], map: "subj_course")
}

model Faculty {
Expand Down

0 comments on commit 54cc6c1

Please sign in to comment.