From f78b0cd8a3f6a97357f5f46422de57a369d01eed Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Thu, 14 Nov 2024 00:15:23 +0100 Subject: [PATCH] Fix text similarity searches --- plugins/imaging.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/imaging.py b/plugins/imaging.py index f1409bf..1c9d24e 100644 --- a/plugins/imaging.py +++ b/plugins/imaging.py @@ -254,10 +254,10 @@ async def robot9000(self, ctx: commands.Context, *, text_query: Optional[str] = with data.session() as session: for image9000, textual_similarity in ( session.query(Image9000) - .add_column(Image9000.text.op('<%')(text_query).label("textual_similarity")) + .add_column(func.word_similarity(text_query, Image9000.text).label("textual_similarity")) .filter( Image9000.server_id == ctx.guild.id, - Image9000.text.op('<%')(text_query) + Image9000.text.op('%>')(text_query) ) .order_by(desc("textual_similarity")) .limit(20) @@ -309,7 +309,7 @@ async def robot9000(self, ctx: commands.Context, *, text_query: Optional[str] = if base_image9000.text and len(base_image9000.text) >= self.IMAGE9000_TEXTUAL_SIMILARITY_MIN_CHARS: textual_similarity_column = func.word_similarity( - Image9000.text, base_image9000.text + base_image9000.text, Image9000.text ).label("textual_similarity") perceptual_matches = ( server_images @@ -323,7 +323,7 @@ async def robot9000(self, ctx: commands.Context, *, text_query: Optional[str] = server_images .add_column(perceptual_distance_column) .add_column(textual_similarity_column) - .filter(Image9000.text.op('<%')(base_image9000.text)) + .filter(Image9000.text.op('%>')(base_image9000.text)) ) for other_image9000, perceptual_distance, textual_similarity in ( perceptual_matches.union(textual_matches).distinct()