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

Search / Filter Functionality #1

Open
manzil-infinity180 opened this issue Mar 5, 2024 · 4 comments
Open

Search / Filter Functionality #1

manzil-infinity180 opened this issue Mar 5, 2024 · 4 comments

Comments

@manzil-infinity180
Copy link
Owner

  • user can search the job throught the tech stack , role of job/intern , salary , type - intern/job , remote , onsite

  • user can also sort the search / filter using the experience needed for applying the job/ intern

  • as you know our sys is depend on coins or charge so user can also sort throught the coins/ charge so they can easily apply to it

@manzil-infinity180
Copy link
Owner Author

@manzil-infinity180
Copy link
Owner Author

manzil-infinity180 commented Mar 7, 2024

** JSON indexes for autocomplete
It will do the autocomplete for the filed name - "roleName"

// this is on the mongodb atlas

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "roleName": [
        {
          "foldDiacritics": false,
          "maxGrams": 7,
          "minGrams": 3,
          "tokenization": "edgeGram",
          "type": "autocomplete"
        }
      ]
    }
  }
}


  • How the code will look like if we implement the think into the code for any route
exports.autoComplete = async(req,res,next)=>{
  try{

    let result = [];
    results = await Job.aggregate([
      {
        '$search': {
          'index': 'autoComplete', 
          'autocomplete': {
            'query': req.params.autocomplete, 
            'path': "roleName",
            "tokenOrder":"sequential"
          }
        }
      }, {
        '$limit': 10
      }, {
        '$project': {
          'roleName': 1,
        }
      }
    ])
    
    res.status(200).json({
      status:"success",
      data : {results}
    })

  }catch(err){
    res.status(404).json({
      status:"Failed",
      data:{
        err:err.message
      }
    })
  }
}



@manzil-infinity180
Copy link
Owner Author

for the search field it will look like this

exports.searchField = async(req,res,next)=>{
  try{
    console.log(req.params.search);
    console.log(req.query.name);
    let results = [];
     results = await Job.aggregate([
      { $search: {
          index: 'default',
          text: {
            query: req.params.search,
            path:["companyname","roleName"],
            // path:{
            //   wildcard:"*"
            // },
            fuzzy:{}
          }
        }
      }
    ]);
    console.log(results);

    res.status(200).json({
      data : {results}
    })

  }catch(err){
    
    res.status(404).json({
      status:"Failed",
      data:{
        err:err.message
      }
    })

  }
}

@manzil-infinity180
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant