def searchAll(rawinputs, asyncSearch=True, dummySearch=False): """Search all known collections for the given input dictionary.""" from multiprocessing.pool import ThreadPool pool = ThreadPool(processes=8) async_handles = [] results = {} for inst in archivesList: for coll in inst['collections']: classname = coll['class'] import sys module = sys.modules[__name__] collClass = getattr(module, classname) collObject = collClass() if dummySearch: # use dummy collection that does no search.. collObject = Dummy() collObject.setClassName(classname) # NOTE: presence of info.fields indicates advanced search support if hasattr(collObject, 'info'): if 'fields' in collObject.info: inputs = rawinputs else: inputs = '' for key in rawinputs: if(len(rawinputs[key].strip()) > 0): if( len(inputs) > 0 ): inputs += ' '+rawinputs[key] else: inputs += rawinputs[key] else: inputs = '' for key in rawinputs: if(len(rawinputs[key].strip()) > 0): if( len(inputs) > 0 ): inputs += ' '+rawinputs[key] else: inputs += rawinputs[key] if asyncSearch: handle = pool.apply_async(collObject.keywordResultsCount, (inputs,)) async_handles.append(handle) else: resultcoll = collObject.keywordResultsCount(inputs) result_dict = resultcoll.emit() results[result_dict['class']] = result_dict if asyncSearch: for res in async_handles: try: resultcoll = res.get(timeout=15) except Exception, e: logging.exception(e) resultcoll = None pass if resultcoll != None: result_dict = resultcoll.emit() results[result_dict['class']] = result_dict