Skip to content

Commit

Permalink
Fix full-text search query
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Dec 28, 2020
1 parent 257a396 commit a64f932
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ def search_keyword(cls, query, lim=100):
if not query or query == "*":
return []

# !!! FIXME !!! Fix GROUP BY for entries without infohash !!!
# TODO: optimize this query by removing unnecessary select nests (including Pony-manages selects)
fts_ids = raw_sql(
"""SELECT rowid FROM ChannelNode WHERE rowid IN (SELECT rowid FROM FtsIndex WHERE FtsIndex MATCH $query
ORDER BY bm25(FtsIndex) LIMIT $lim) GROUP BY infohash"""
ORDER BY bm25(FtsIndex) LIMIT $lim) GROUP BY coalesce(infohash, rowid)"""
)
return left_join(g for g in cls if g.rowid in fts_ids) # pylint: disable=E1135

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,13 @@ def save():
channel_pk=channel.public_key, txt_filter='aaa', sort_by='HEALTH', sort_desc=True
)
titles = [obj.title.partition(' ')[0] for obj in objects]
# FIXME: does not return folder2 and folder2_1 due to a bug in a full text search query
assert titles == ['torrent2_1', 'torrent1', 'folder1']
assert titles == ['torrent2_1', 'torrent1', 'folder2_1', 'folder2', 'folder1']

objects = metadata_store.MetadataNode.get_entries(
channel_pk=channel.public_key, txt_filter='aaa', sort_by='HEALTH', sort_desc=False
)
titles = [obj.title.partition(' ')[0] for obj in objects]
# FIXME: does not return folder2 and folder2_1 due to a bug in a full text search query
assert titles == ['folder1', 'torrent1', 'torrent2_1']
assert titles == ['folder1', 'folder2', 'folder2_1', 'torrent1', 'torrent2_1']

objects = metadata_store.MetadataNode.get_entries(
origin_id=channel.id_,
Expand All @@ -565,15 +563,13 @@ def save():
sort_desc=True,
)
titles = [obj.title.partition(' ')[0] for obj in objects]
# FIXME: does not return folder2 due to a bug in a full text search query
assert titles == ['torrent1', 'folder1']
assert titles == ['torrent1', 'folder2', 'folder1']

objects = metadata_store.MetadataNode.get_entries(
origin_id=channel.id_, txt_filter='aaa', sort_by='HEALTH', sort_desc=False
)
titles = [obj.title.partition(' ')[0] for obj in objects]
# FIXME: does not return folder2 due to a bug in a full text search query
assert titles == ['folder1', 'torrent1']
assert titles == ['folder1', 'folder2', 'torrent1']


@db_session
Expand Down

0 comments on commit a64f932

Please sign in to comment.