Created
March 2, 2021 06:29
-
-
Save sebastjan-hribar/fc4728104d15d087a0938b144d4fc68b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aggregation | |
SELECT "id", "language_id", "content", "created_at", "updated_at", | |
SIMILARITY("content", 'I''m light as a frog') AS "similarity" FROM "segments" | |
WHERE (("language_id" = 5) AND (similarity("content", 'I''m light as a frog') > 0.45)) | |
ORDER BY SIMILARITY("content", 'I''m light as a frog') | |
DESC | |
SELECT "translation_records"."id", "translation_records"."source_segment_id", | |
"translation_records"."target_segment_id", "translation_records"."domain_id", | |
"translation_records"."style_id", "translation_records"."project_name", | |
"translation_records"."created_at", "translation_records"."updated_at", | |
"translation_records"."language_combination", | |
"translation_records"."uid" FROM "translation_records" | |
INNER JOIN "segments" ON ("segments"."id" = "translation_records"."source_segment_id") | |
WHERE ("translation_records"."source_segment_id" IN (113, 115)) ORDER BY "translation_records"."id" | |
# Returned | |
[ | |
{ | |
:id=>113, :language_id=>5, :content=>"I'm light as a bird.", :created_at=>2021-02-28 14:11:17 UTC, | |
:updated_at=>2021-02-28 14:11:17 UTC, :similarity=>0.583333, | |
:translation_records=> | |
[ | |
{ | |
:id=>57, :source_segment_id=>113, :target_segment_id=>114, :domain_id=>2, :style_id=>4, | |
:project_name=>"Rjavina", :created_at=>2021-02-28 14:11:17 UTC, | |
:updated_at=>2021-02-28 14:11:17 UTC, :language_combination=>"5_4", :uid=>"113_114_5_4_2_4" | |
} | |
] | |
}, | |
{ | |
:id=>115, :language_id=>5, :content=>"I'm light as a dodo.", :created_at=>2021-02-28 16:16:21 UTC, | |
:updated_at=>2021-02-28 16:16:21 UTC, :similarity=>0.583333, | |
:translation_records=> | |
[ | |
{ | |
:id=>58, :source_segment_id=>115, :target_segment_id=>116, :domain_id=>2, :style_id=>4, | |
:project_name=>"Rjavina", :created_at=>2021-02-28 16:16:21 UTC, | |
:updated_at=>2021-02-28 16:16:21 UTC, :language_combination=>"5_4", :uid=>"115_116_5_4_2_4" | |
} | |
] | |
} | |
] | |
--- | |
# Without aggregation | |
SELECT "id", "language_id", "content", "created_at", "updated_at", | |
SIMILARITY("content", 'I''m light as a frog') AS "similarity" FROM "segments" | |
WHERE (("language_id" = 5) AND (similarity("content", 'I''m light as a frog') > 0.45)) | |
ORDER BY SIMILARITY("content", 'I''m light as a frog') | |
DESC | |
# Returned | |
[ | |
#<Segment:0x000055aab0009898 | |
@attributes= | |
{ | |
:id=>113, :language_id=>5, :content=>"I'm light as a bird.", | |
:created_at=>2021-02-28 14:11:17 UTC, :updated_at=>2021-02-28 14:11:17 UTC | |
}>, | |
#<Segment:0x000055aaaffcf788 | |
@attributes= | |
{ | |
:id=>115, :language_id=>5, :content=>"I'm light as a dodo.", | |
:created_at=>2021-02-28 16:16:21 UTC, :updated_at=>2021-02-28 16:16:21 UTC | |
}> | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment