def search_one(self, query, split_regexp, key):
query = re.split(split_regexp, query)
#print("Query: ", query)
if len(query)>7:
return None
dbs = []
if "cpp" in query:
dbs = [db_cpp]
query.remove("cpp")
elif "c++" in query:
dbs = [db_cpp]
query.remove("c++")
elif "python" in query:
dbs = [db_python3]
query.remove("python")
elif "python3" in query:
dbs = [db_python3]
query.remove("python3")
else:
dbs = [db_cpp, db_python3]
#print("Query: '", query, "'")
query = filter(lambda x: x, query)
if key == "name":
query = sorted(query)
query = " ".join(query)
#print("Query: '", query, "'")
#print("dbs: ", str(dbs))
found = False
for db in dbs:
#print("db: ", str(db))
cursor = db.index.find({key : query}, sort=[("relevance", pymongo.DESCENDING)])
for doc in cursor:
found = True
need_continue = self.found_reference(db, doc)
if not need_continue:
break
return found
评论列表
文章目录