def __init__(self, search_query): # init vars super().__init__() self.search_query = search_query self.result_container = ResultContainer() self.start_time = None self.actual_timeout = None
def test_result_merge(self): c = ResultContainer() c.extend('wikipedia', [fake_result()]) c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')]) self.assertEqual(c.results_length(), 2)
def search(self, search_query: SearchQuery) -> ResultContainer: result_container = ResultContainer() engineref_category = search_query.engineref_list[0].category params = self.processor.get_params(search_query, engineref_category) if params is not None: counter_inc('engine', search_query.engineref_list[0].name, 'search', 'count', 'sent') self.processor.search(search_query.query, params, result_container, default_timer(), 5) return result_container
def search(self, search_query: SearchQuery) -> ResultContainer: result_container = ResultContainer() engineref_category = search_query.engineref_list[0].category params = self.processor.get_params(search_query, engineref_category) if params is not None: with threading.RLock(): self.processor.engine.stats['sent_search_count'] += 1 self.processor.search(search_query.query, params, result_container, time(), 5) return result_container
def __init__(self, search_query): # init vars super(Search, self).__init__() self.search_query = search_query self.result_container = ResultContainer()
def __init__(self, request): # init vars super(Search, self).__init__() self.query = None self.engines = [] self.categories = [] self.paging = False self.pageno = 1 self.lang = 'all' # set blocked engines self.blocked_engines = request.preferences.engines.get_disabled() self.result_container = ResultContainer() self.request_data = {} # set specific language if set self.lang = request.preferences.get_value('language') # set request method if request.method == 'POST': self.request_data = request.form else: self.request_data = request.args # TODO better exceptions if not self.request_data.get('q'): raise Exception('noquery') # set pagenumber pageno_param = self.request_data.get('pageno', '1') if not pageno_param.isdigit() or int(pageno_param) < 1: pageno_param = 1 self.pageno = int(pageno_param) # parse query, if tags are set, which change # the serch engine or search-language query_obj = Query(self.request_data['q'], self.blocked_engines) query_obj.parse_query() # set query self.query = query_obj.getSearchQuery() # get last selected language in query, if possible # TODO support search with multible languages if len(query_obj.languages): self.lang = query_obj.languages[-1] self.engines = query_obj.engines self.categories = [] # if engines are calculated from query, # set categories by using that informations if self.engines and query_obj.specific: self.categories = list( set(engine['category'] for engine in self.engines)) # otherwise, using defined categories to # calculate which engines should be used else: # set categories/engines load_default_categories = True for pd_name, pd in self.request_data.items(): if pd_name == 'categories': self.categories.extend( categ for categ in map(unicode.strip, pd.split(',')) if categ in categories) elif pd_name == 'engines': pd_engines = [{ 'category': engines[engine].categories[0], 'name': engine } for engine in map(unicode.strip, pd.split(',')) if engine in engines] if pd_engines: self.engines.extend(pd_engines) load_default_categories = False elif pd_name.startswith('category_'): category = pd_name[9:] # if category is not found in list, skip if category not in categories: continue if pd != 'off': # add category to list self.categories.append(category) elif category in self.categories: # remove category from list if property is set to 'off' self.categories.remove(category) if not load_default_categories: if not self.categories: self.categories = list( set(engine['category'] for engine in self.engines)) return # if no category is specified for this search, # using user-defined default-configuration which # (is stored in cookie) if not self.categories: cookie_categories = request.cookies.get('categories', '') cookie_categories = cookie_categories.split(',') for ccateg in cookie_categories: if ccateg in categories: self.categories.append(ccateg) # if still no category is specified, using general # as default-category if not self.categories: self.categories = ['general'] # using all engines for that search, which are # declared under the specific categories for categ in self.categories: self.engines.extend({ 'category': categ, 'name': engine.name } for engine in categories[categ] if (engine.name, categ) not in self.blocked_engines) # remove suspended engines self.engines = [ e for e in self.engines if engines[e['name']].suspend_end_time <= time() ]
def test_one_suggestion(self): c = ResultContainer() c.extend('wikipedia', [fake_result(suggestion=True)]) self.assertEqual(len(c.suggestions), 1) self.assertEqual(c.results_length(), 0)
def test_one_result(self): c = ResultContainer() c.extend('wikipedia', [fake_result()]) self.assertEqual(c.results_length(), 1)
def test_empty(self): c = ResultContainer() self.assertEqual(c.get_ordered_results(), [])