Created
October 22, 2020 21:30
-
-
Save mkhorasani/41aee4e290d63ae4350064455b3edb4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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