From 51f8c56ace536fdc1cacd0754800ecca66af0071 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovsky Date: Mon, 1 Nov 2021 06:58:39 +0100 Subject: [PATCH] Fixes #6514: Move to_fts_query to tribler_common.utilities from tribler_gui.utilities --- src/tribler-common/tribler_common/utilities.py | 11 +++++++++++ .../restapi/tests/test_search_endpoint.py | 4 ++-- src/tribler-gui/tribler_gui/utilities.py | 9 --------- .../tribler_gui/widgets/searchresultswidget.py | 3 ++- .../tribler_gui/widgets/tablecontentmodel.py | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/tribler-common/tribler_common/utilities.py b/src/tribler-common/tribler_common/utilities.py index 27a385fb2f5..2563ac13e3f 100644 --- a/src/tribler-common/tribler_common/utilities.py +++ b/src/tribler-common/tribler_common/utilities.py @@ -1,4 +1,5 @@ import os +import re import sys from pathlib import Path from urllib.parse import urlparse @@ -21,3 +22,13 @@ def uri_to_path(uri): parsed = urlparse(uri) host = "{0}{0}{mnt}{0}".format(os.path.sep, mnt=parsed.netloc) return Path(host) / url2pathname(parsed.path) + + +fts_query_re = re.compile(r'\w+', re.UNICODE) + + +def to_fts_query(text): + if not text: + return "" + words = fts_query_re.findall(text) + return ' '.join(f'"{word}"' for word in words) + '*' diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py index d3364a0fc03..59cdcdf1b48 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_search_endpoint.py @@ -4,12 +4,12 @@ import pytest +from tribler_common.utilities import to_fts_query + from tribler_core.components.metadata_store.restapi.search_endpoint import SearchEndpoint from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.utilities.random_utils import random_infohash -from tribler_gui.utilities import to_fts_query - # pylint: disable=unused-argument, redefined-outer-name diff --git a/src/tribler-gui/tribler_gui/utilities.py b/src/tribler-gui/tribler_gui/utilities.py index 76d21e0660c..0e849775bfb 100644 --- a/src/tribler-gui/tribler_gui/utilities.py +++ b/src/tribler-gui/tribler_gui/utilities.py @@ -2,7 +2,6 @@ import logging import math import os -import re import sys import traceback import types @@ -435,11 +434,3 @@ def get_translator(language=None): filename = "" translator.load(locale, filename, directory=TRANSLATIONS_DIR) return translator - -fts_query_re = re.compile(r'\w+', re.UNICODE) - -def to_fts_query(text): - if not text: - return "" - words = fts_query_re.findall(text) - return ' '.join(f'"{word}"' for word in words) + '*' diff --git a/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py b/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py index 736ebd4fe0e..582b25b3845 100644 --- a/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py +++ b/src/tribler-gui/tribler_gui/widgets/searchresultswidget.py @@ -7,11 +7,12 @@ from PyQt5.QtCore import pyqtSignal from tribler_common.sentry_reporter.sentry_mixin import AddBreadcrumbOnShowMixin +from tribler_common.utilities import to_fts_query from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT from tribler_gui.tribler_request_manager import TriblerNetworkRequest -from tribler_gui.utilities import connect, get_ui_file_path, to_fts_query, tr +from tribler_gui.utilities import connect, get_ui_file_path, tr from tribler_gui.widgets.tablecontentmodel import SearchResultsModel widget_form, widget_class = uic.loadUiType(get_ui_file_path('search_results.ui')) diff --git a/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py b/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py index ea74319d1df..6c9be4fce53 100644 --- a/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py +++ b/src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py @@ -7,6 +7,7 @@ from PyQt5.QtCore import QAbstractTableModel, QModelIndex, QRectF, QSize, Qt, pyqtSignal from tribler_common.simpledefs import CHANNELS_VIEW_UUID, CHANNEL_STATE +from tribler_common.utilities import to_fts_query from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT @@ -19,7 +20,6 @@ format_votes, get_votes_rating_description, pretty_date, - to_fts_query, tr, )