Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
how to do search functionality

Please help me out. I'm making a search functionality. Below is My Code and User stories. I'm able to pass only the first User Story but not with the other stories. Can someone please help me out.

User Stories:

  1. As an User if I search with Skills and location I should get the results which matched with the query.

  2. As an User if I search with only Skills still I should get the results which matched with the query.

  3. As an User if I search with only Location still I should get the results which matched with the query.

  4. As an User if I search with invalid skills (J, A, B) or location I shouldn't get the results which does matched the query..

    var search = {
     get: function (req, res) {
        var locationQuery = req.params.locationQuery,
        skillsQuery = req.params.skillsQuery;
    
        Jobs.find({state: { "$regex": locationQuery, "$options": "i" }, Skills: { "$regex": skillsQuery, "$options": "i" }}, function(err, result) {
            if (err) {
                console.log('Not a Valid Search');
                res.status(500).send(err, 'Not a Valid Search');
            }else {
                res.json(result);
            }            
        });
     }
    };
    
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For this kind of optional support, It would be better to take search parameters as query in GET. You can take reference of the following code snippet.

var search = {
 get: function (req, res) {
    var query = {};
    if(req.query.locationQuery){
      query.state = { "$regex": req.query.locationQuery, "$options": "i" };
    }
    if(req.query.skillsQuery){
      query.Skills = { "$regex": req.query.skillsQuery, "$options": "i" }
    }

    Jobs.find(query, function(err, result) {
        if (err) {
            console.log('Not a Valid Search');
            res.status(500).send(err, 'Not a Valid Search');
        }else {
            res.json(result);
        }            
    });
 }
};

Upadte:

Define your route as: searchRoute.get('/', search.get);

And you can send your query parameters as(through POSTMAN):

localhost:3000/api/search/?skillsQuery="java,javascript"&lo‌​cationQuery="Mumbai

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!