def build_search_index_run(): app_search = AppSearch() try: app_search.create_index() except: pass num_apps_per_process = 50000 fields = { "trackName": 1, "bundleId": 1, "supportedDevices": 1, "artworkUrl512": 1, "averageUserRating": 1, "sign": 1, "fileSizeBytes": 1, "downloadVersion": 1, "downloadCount": 1, } apps = [] processes = [] for index, app in enumerate(mongo_db.AppBase.find({"review": 1}, fields)): apps.append(app) if (index + 1) % num_apps_per_process == 0: p = multiprocessing.Process(target=index_process_worker, args=(app_search, apps)) p.start() processes.append(p) apps = [] p = multiprocessing.Process(target=index_process_worker, args=(app_search, apps)) p.start() processes.append(p) for process in processes: process.join() app_search.refresh()
def do_request(self): words = request.args.get('q', None) try: page = int(request.args.get('page', 1)) except: page = 1 try: device = int(request.args.get('device', 1)) except: device = 1 num = request.args.get('num', 4) search = AppSearch() res = search.query(words, device, self._view._sign, page, 12, self._view._language) return self._view.render(1000, res)