Merge remote-tracking branch 'origin/search' into api

This commit is contained in:
Muneeb Ali
2017-04-03 09:42:34 -04:00
5 changed files with 55 additions and 9 deletions

View File

@@ -25,8 +25,10 @@ $ sudo service mongodb start
$ sudo pip install uwsgi
$ virtualenv search
$ git clone https://github.com/blockstack/blockstack-core.git
$ cd blockstack-core/
$ git checkout search
$ cd blockstack-core/api/search/
$ cd api/search/
$ mkdir data
$ pip install -r requirements.txt
$ python runserver.py
```

View File

@@ -10,7 +10,7 @@ itsdangerous==0.24
proofchecker==0.0.2
pybitcoin==0.9.5
pybitcointools==1.1.15
pylibmc==1.5.0
pylibmc==1.5.2
pymongo==3.0.3
python-bitcoinrpc==0.1
requests==2.8.1

View File

@@ -30,7 +30,7 @@ import requests
from pymongo import MongoClient
from .utils import validUsername
from .utils import get_json, config_log
from .utils import get_json, config_log, pretty_print
from .config import BLOCKCHAIN_DATA_FILE, PROFILE_DATA_FILE
@@ -173,6 +173,19 @@ def create_search_index():
profile = get_json(user['profile'])
hasBazaarId=False
# search for openbazaar id in the profile
if 'account' in profile:
for accounts in profile['account']:
if accounts['service'] == 'openbazaar':
hasBazaarId = True
search_profile['openbazaar']=accounts['identifier']
# pretty_print(search_profile['openbazaar'])
if (hasBazaarId == False):
search_profile['openbazaar'] = None
if 'name' in profile:
try:
@@ -192,6 +205,7 @@ def create_search_index():
search_profile['name'] = None
if 'twitter' in profile:
twitter_handle = profile['twitter']
try:
@@ -214,6 +228,9 @@ def create_search_index():
search_profile['profile'] = profile
search_profiles.save(search_profile)
# dedup names
people_names = list(set(people_names))
people_names = {'name': people_names}
@@ -225,6 +242,9 @@ def create_search_index():
usernames = {'username': usernames}
# save final dedup results to mongodb (using it as a cache)
people_cache.save(people_names)
twitter_cache.save(twitter_handles)
username_cache.save(usernames)
@@ -233,7 +253,7 @@ def create_search_index():
log.debug('Created name/twitter/username search index')
if __name__ == "__main__":
if(len(sys.argv) < 2):

View File

@@ -32,7 +32,7 @@ from .utils import get_json, config_log
from .config import BLOCKCHAIN_DATA_FILE, PROFILE_DATA_FILE
from blockstack_client.proxy import get_all_names
from blockstack_client.profile import get_name_profile
from blockstack_client.profile import get_profile
log = config_log(__name__)
@@ -77,7 +77,7 @@ def fetch_profiles():
resp['fqu'] = fqu
try:
resp['profile'] = get_name_profile(fqu)[0]
resp['profile'] = get_profile(fqu)[0]
all_profiles.append(resp)
except:
pass

View File

@@ -40,7 +40,7 @@ from search.db import search_db, search_profiles
from search.db import search_cache
from search.config import DEFAULT_LIMIT
from .utils import get_json,pretty_print
def anyword_substring_search_inner(query_word, target_words):
""" return True if ANY target_word matches a query_word
@@ -109,6 +109,18 @@ def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
return matching
def search_people_by_GUID(query, limit_results=DEFAULT_LIMIT):
result={}
for entry in search_profiles.find({"openbazaar":query}, {"profile":1,"username" : 1}):
result["profile"] = entry["profile"]
result["username"] = entry["username"]
pretty_print(result)
def search_people_by_name(query, limit_results=DEFAULT_LIMIT):
query = query.lower()
@@ -116,9 +128,13 @@ def search_people_by_name(query, limit_results=DEFAULT_LIMIT):
people_names = []
# using mongodb as a cache, load data in people_names
for i in search_cache.people_cache.find():
people_names += i['name']
results = substring_search(query, people_names, limit_results)
return order_search_results(query, results)
@@ -129,11 +145,14 @@ def search_people_by_twitter(query, limit_results=DEFAULT_LIMIT):
query = query.lower()
twitter_handles = []
# using mongodb as a cache, load data
for i in search_cache.twitter_cache.find():
twitter_handles += i['twitter_handle']
results = substring_search(query, twitter_handles, limit_results)
return results
@@ -315,11 +334,16 @@ if __name__ == "__main__":
print '-' * 5
print fetch_profiles(name_search_results, search_type="name")
elif(option == '--search_twitter'):
query = sys.argv[2]
twitter_search_results = search_people_by_twitter(query, DEFAULT_LIMIT)
print twitter_search_results
print '-' * 5
print fetch_profiles(twitter_search_results, search_type="twitter")
elif(option == '--search_GUID'):
print "searching by GUID"
query = sys.argv[2]
search_people_by_GUID(query, DEFAULT_LIMIT)
elif(option == '--search_username'):
query = sys.argv[2]
username_search_results = search_people_by_username(query, DEFAULT_LIMIT)