Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda