Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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);
            }            
        });
     }
    };
    
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda