Skip to content

Commit

Permalink
The limiter of the number of results of the image category was added
Browse files Browse the repository at this point in the history
  • Loading branch information
mehr32 committed Dec 6, 2023
1 parent 80e3e63 commit 7f1566b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions searx/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class ResultContainer:
'engine_data',
'on_result',
'_lock',
'Number_Images',
'Image_category_limiter',
)

def __init__(self):
Expand All @@ -188,7 +190,8 @@ def __init__(self):
self.redirect_url = None
self.on_result = lambda _: True
self._lock = RLock()

self.Number_Images = 16
self.Image_category_limiter = True
def extend(self, engine_name, results):
if self._closed:
return
Expand Down Expand Up @@ -366,12 +369,21 @@ def close(self):
# pass 2 : group results by category and template
gresults = []
categoryPositions = {}
Zero_Value = 0

for res in results:
# FIXME : handle more than one category per engine
engine = engines[res['engine']]
res['category'] = engine.categories[0] if len(engine.categories) > 0 else ''

# Limit the number of results of images category
if self.Image_category_limiter:
Categoryـstorage = engine.categories[0] if len(engine.categories) > 0 else ''
if Categoryـstorage == 'images' and Zero_Value < self.Number_Images:
Zero_Value += 1
elif Categoryـstorage == 'images' and Zero_Value >= self.Number_Images:
continue

res['category'] = engine.categories[0] if len(engine.categories) > 0 else ''
# FIXME : handle more than one category per engine
category = (
res['category']
Expand Down

0 comments on commit 7f1566b

Please sign in to comment.