Skip to content

Instantly share code, notes, and snippets.

@mkhorasani
Created October 22, 2020 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhorasani/41aee4e290d63ae4350064455b3edb4d to your computer and use it in GitHub Desktop.
Save mkhorasani/41aee4e290d63ae4350064455b3edb4d to your computer and use it in GitHub Desktop.
client = pymongo.MongoClient("mongodb+srv://test:<password>@cluster0.nq0me.mongodb.net/<dbname>?retryWrites=true&w=majority")
def query(country,keywords):
result = client['database1']['collection1'].aggregate([
{
'$search': {
'text': {
'path': [
'industry'
],
'query': [
' %s' % (keywords)
],
'fuzzy': {
'maxEdits': 2,
'prefixLength': 2
}
}
}
}, {
'$project': {
'Name': '$name',
'URL': '$domain',
'Industry': '$industry',
'University': '$Uni',
'City': '$locality',
'Country': '$country',
'score': {
'$meta': 'searchScore'
}
}
}, {
'$match': {
'Country': '%s' % (country)
}
}, {
'$limit': 10
}
])
df = pd.DataFrame(result)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment