on master help sign in
fix Wikipedia's paragraph extraction
77b9faaMarc Abonce Seguin
searx/engines/wikipedia.py+1−27
@@ -49,29 +49,6 @@ def request(query, params):
49 return params
49 return params
50
50
51
51
52−# get first meaningful paragraph
53−# this should filter out disambiguation pages and notes above first paragraph
54−# "magic numbers" were obtained by fine tuning
55−def extract_first_paragraph(content, title, image):
56− first_paragraph = None
57−
58− failed_attempts = 0
59− for paragraph in content.split('\n'):
60−
61− starts_with_title = paragraph.lower().find(title.lower(), 0, len(title) + 35)
62− length = len(paragraph)
63−
64− if length >= 200 or (starts_with_title >= 0 and (image or length >= 150)):
65− first_paragraph = paragraph
66− break
67−
68− failed_attempts += 1
69− if failed_attempts > 3:
70− return None
71−
72− return first_paragraph
73−
74−
75# get response from search-request
52# get response from search-request
76def response(resp):
53def response(resp):
77 results = []
54 results = []
@@ -97,10 +74,7 @@ def response(resp):
97 if image:
74 if image:
98 image = image.get('source')
75 image = image.get('source')
99
76
100− extract = page.get('extract')
77+ summary = page.get('extract', '').split('\n')[0].replace('()', '')
101−
102− summary = extract_first_paragraph(extract, title, image)
103− summary = summary.replace('() ', '')
104
78
105 # link to wikipedia article
79 # link to wikipedia article
106 wikipedia_link = base_url.format(language=url_lang(resp.search_params['language'])) \
80 wikipedia_link = base_url.format(language=url_lang(resp.search_params['language'])) \