Skip to content

Commit

Permalink
Fix text similarity searches
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Nov 13, 2024
1 parent 2bffa9f commit f78b0cd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugins/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit f78b0cd

Please sign in to comment.