Skip to content

Commit

Permalink
Fixes #6514: Move to_fts_query to tribler_common.utilities from tribl…
Browse files Browse the repository at this point in the history
…er_gui.utilities
  • Loading branch information
kozlovsky committed Nov 1, 2021
1 parent 9f9a2ec commit 51f8c56
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/tribler-common/tribler_common/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import sys
from pathlib import Path
from urllib.parse import urlparse
Expand All @@ -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) + '*'
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 0 additions & 9 deletions src/tribler-gui/tribler_gui/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import math
import os
import re
import sys
import traceback
import types
Expand Down Expand Up @@ -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) + '*'
3 changes: 2 additions & 1 deletion src/tribler-gui/tribler_gui/widgets/searchresultswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +20,6 @@
format_votes,
get_votes_rating_description,
pretty_date,
to_fts_query,
tr,
)

Expand Down

0 comments on commit 51f8c56

Please sign in to comment.