SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
Merge branch 'comments' of https://github.com/pointhi/searx
Adam Tauberbd2db71fa692
diff --cc searx/search.pyindex cc755a6b0,d2a9dd42f..c861a795a--- a/searx/search.py+++ b/searx/search.py@@@ -32,8 -59,11 +59,11 @@@ def make_callback(engine_name, resultsprint '[E] Error with engine "{0}":\n\t{1}'.format(engine_name, str(e))return-++for result in search_results:result['engine'] = engine_name++ # if it is a suggestion, add it to list of suggestionsif 'suggestion' in result:# TODO type checkssuggestions.add(result['suggestion'])@@@ -48,9 -84,10 +84,10 @@@ def score_results(results)None, chain.from_iterable(izip_longest(*results.values())))flat_len = len(flat_res)engines_len = len(results)+results = []- # deduplication + scoring+ # pass 1: deduplication + scoringfor i, res in enumerate(flat_res):res['parsed_url'] = urlparse(res['url'])@@@ -91,42 -146,9 +146,43 @@@else:res['score'] = scoreresults.append(res)+- # return results sorted by score- return sorted(results, key=itemgetter('score'), reverse=True)+ results = sorted(results, key=itemgetter('score'), reverse=True)++ # pass 2 : group results by category and template+ gresults = []+ categoryPositions = {}++ for i, res in enumerate(results):+ # FIXME : handle more than one category per engine- category = engines[res['engine']].categories[0] + ':' + '' if 'template' not in res else res['template']++ category = engines[res['engine']].categories[0] + ':' + '' if 'template' not in res else res['template']++ current = None if category not in categoryPositions else categoryPositions[category]++ # group with previous results using the same category if the group can accept more result and is not too far from the current position+ if current != None and (current['count'] > 0) and (len(gresults) - current['index'] < 20):+ # group with the previous results using the same category with this one+ index = current['index']+ gresults.insert(index, res)++ # update every index after the current one (including the current one)+ for k in categoryPositions:+ v = categoryPositions[k]['index']+ if v >= index:+ categoryPositions[k]['index'] = v+1++ # update this category+ current['count'] -= 1++ else:+ # same category+ gresults.append(res)++ # update categoryIndex+ categoryPositions[category] = { 'index' : len(gresults), 'count' : 8 }++ # return gresults+ return gresultsclass Search(object):