From 2aef38c3b9d1fe93e9d665a49b10151d63d92392 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 26 Oct 2020 13:33:40 +0100 Subject: [PATCH] [fix] resolve query_parts regression --- searx/query.py | 9 ++++----- tests/unit/test_query.py | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/searx/query.py b/searx/query.py index d82493141..7effda15a 100644 --- a/searx/query.py +++ b/searx/query.py @@ -59,8 +59,6 @@ class RawTextQuery: # part does only contain spaces, skip if query_part.isspace()\ or query_part == '': - searx_query_part = True - self.query_parts.append(query_part) continue # this force the timeout @@ -147,8 +145,9 @@ class RawTextQuery: self.specific = True # append query part to query_part list - self.query_parts.append(query_part) - if not searx_query_part: + if searx_query_part: + self.query_parts.append(query_part) + else: self.user_query_parts.append(query_part) def changeQuery(self, query): @@ -160,4 +159,4 @@ class RawTextQuery: def getFullQuery(self): # get full querry including whitespaces - return ''.join(self.query_parts) + return '{0} {1}'.format(''.join(self.query_parts), self.getQuery()).strip() diff --git a/tests/unit/test_query.py b/tests/unit/test_query.py index d682876c0..eff4d643c 100644 --- a/tests/unit/test_query.py +++ b/tests/unit/test_query.py @@ -9,7 +9,8 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), query_text) - self.assertEqual(len(query.query_parts), 3) + self.assertEqual(len(query.query_parts), 0) + self.assertEqual(len(query.user_query_parts), 2) self.assertEqual(len(query.languages), 0) self.assertFalse(query.specific) @@ -20,7 +21,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) self.assertEqual(query.getFullQuery(), full_query) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertEqual(len(query.languages), 1) self.assertIn(language, query.languages) self.assertFalse(query.specific) @@ -32,7 +33,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) self.assertEqual(query.getFullQuery(), full_query) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertIn('en', query.languages) self.assertFalse(query.specific) @@ -43,7 +44,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) self.assertEqual(query.getFullQuery(), full_query) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertIn('all', query.languages) self.assertFalse(query.specific) @@ -54,7 +55,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) self.assertEqual(query.getFullQuery(), full_query) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 0) self.assertEqual(len(query.languages), 0) self.assertFalse(query.specific) @@ -63,7 +64,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), query_text) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertEqual(query.timeout_limit, 3) self.assertFalse(query.specific) @@ -72,7 +73,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), query_text) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertEqual(query.timeout_limit, 0.35) self.assertFalse(query.specific) @@ -81,7 +82,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), query_text) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 1) self.assertEqual(query.timeout_limit, 3.5) self.assertFalse(query.specific) @@ -91,6 +92,7 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), query_text) - self.assertEqual(len(query.query_parts), 5) + self.assertEqual(len(query.query_parts), 0) + self.assertEqual(query.getQuery(), query_text) self.assertEqual(query.timeout_limit, None) self.assertFalse(query.specific)