Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/seach engine route and controller #15 #65

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions server/controllers/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,33 @@ const companyController = {
next(error)
}
},
searchCompany: async (req, res, next) => {
try {
let companies = await Company.aggregate([
{
$search: {
index: "kinfolk-search",
text: {
query: req.body.search,
path: {
wildcard: "*"
}
}
}
}
]);
// if (companies.length === 1) {
// // If exactly one company matches, return it
// res.json({ redirect: true, company: companies[0] });
// } else {
// // Otherwise, return the list of companies
// res.json({ redirect: false, companies });
// }
res.json(companies); // Send the companies data as JSON response
} catch (error) {
next(error); // Handle errors appropriately
}
}
}

export default companyController
Expand All @@ -101,3 +128,7 @@ export default companyController
// do we want to add the ability to limit the number of results that return when a user searches for all companies?

// Should we add query params so that we can filter through specfic companies returned based on specific atributes?




Loading