Skip to content

Commit

Permalink
try and fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
michelleli01 committed Nov 26, 2023
1 parent 8fd6cdf commit 1deccaa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
34 changes: 21 additions & 13 deletions client/src/modules/Results/Components/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,29 @@ export class Results extends Component {
axios
.post(`/v2/getClassesByQuery`, { query: userQuery })
.then((response) => {
const queryCourseList = response.data.result
if (queryCourseList.length !== 0) {
// Save the Class object that matches the request
this.setState({
courseList: queryCourseList,
loading: false,
})
} else {
this.setState({
courseList: [],
loading: false,
})
if (response.status === 200) {
const queryCourseList = response.data.result
if (queryCourseList.length !== 0) {
// Save the Class object that matches the request
this.setState({
courseList: queryCourseList,
loading: false,
})
} else {
this.setState({
courseList: [],
loading: false,
})
}
}
})
.catch((e) => console.log('Getting courses failed!'))
.catch((e) => {
this.setState({
courseList: [],
loading: false,
})
console.log('Getting courses failed!')
})
}
}

Expand Down
42 changes: 22 additions & 20 deletions client/src/modules/Results/Components/ResultsDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,28 @@ export default class ResultsDisplay extends Component {
? this.state.filteredItems
: this.state.courseList

return items.map((result, index) => (
<div
onClick={() => {
if (this.computeHeight() < 992) {
this.props.history.push(
`/course/${result?.classSub?.toUpperCase()}/${result?.classNum}`
)
}
}}
>
<FilteredResult
key={index}
index={index}
selected={index === this.state.active_card}
course={result}
previewHandler={this.previewHandler}
sortBy={this.state.selected}
/>
</div>
))
if (items.error === undefined | null) {
return items.map((result, index) => (
<div
onClick={() => {
if (this.computeHeight() < 992) {
this.props.history.push(
`/course/${result?.classSub?.toUpperCase()}/${result?.classNum}`
)
}
}}
>
<FilteredResult
key={index}
index={index}
selected={index === this.state.active_card}
course={result}
previewHandler={this.previewHandler}
sortBy={this.state.selected}
/>
</div>
))
}
}

renderCheckboxes(group) {
Expand Down
9 changes: 4 additions & 5 deletions server/src/search/search.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ router.post('/getClassesByQuery', async (req, res) => {
{ sort: { score: { $meta: 'textScore' } } },
).exec();
if (classes && classes.length > 0) {
res.status(200).json({
return res.status(200).json({
message: `Successfully retrieved classes with query ${query}`,
data: classes.sort(courseSort(query)),
});
}

const regexClasses = await regexClassesSearch(query);
// const regexClasses = await regexClassesSearch(query);
res
.status(200)
.status(400)
.json({
message: `Successfully retrieved classes with query ${query} using regex`,
data: regexClasses,
error: `Error retrieved classes with query ${query} using regex`,
});
} catch (error) {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 1deccaa

Please sign in to comment.