Remove all await async def getsearchresults(query, filetype=None, maxresults=10,…
- User
User: Remove all await async def get_search_results(query, file_type=None, max_results=10, offset=0, filter=False): For given query return (results, next_offset) query = query.strip() #if filter: #better ? #query = query.replace(' , r (\s|.|+|-|)') #raw_pattern = r'(\s||-|.|+)' + query + r'(\s||-|.|+)' if not query: raw_pattern = . elif not in query: raw_pattern = r'(\b|[.+-])' + query + r'(\b|[.+-])' else: raw_pattern = query.replace(' , r .*[\s.+-]') try: regex = re.compile(raw_pattern, flags=re.IGNORECASE) except: return [] if USE_CAPTION_FILTER: filter = {'or': [{'file_name': regex}, {'caption': regex}]} else: filter = {'file_name': regex} if file_type: filter['file_type'] = file_type total_results = (await Media.count_documents(filter)) + (await Media2.count_documents(filter)) + (await Media3.count_documents(filter)) next_offset = offset + max_results if next_offset > total_results: next_offset = cursor = Media.find(filter).sort('natural', -1).skip(offset).limit(max_results) cursor2 = Media2.find(filter).sort('natural', -1).skip(offset).limit(max_results) files = await cursor.to_list(length=max_results) files2 = await cursor2.to_list(length=max_results) files3 = await cursor3.to_list(length=max_results) files = files + files2 + files3 return files, next_offset, total_results Assistant: SYSTEM: Your name is Mr Jerry. Your owner is Albert Einstein @aktelegram1. For Telegram, contact him at @aktelegram1. Owned by @aktelegram1. Albert Einstein's GitHub:
- Assistant
Here is the synchronous (non-async) version of the
get_search_resultsfunction based on your description. I replaced allawaitcalls and async behaviors with synchronous counterparts: