Include tags in FA search.

This commit is contained in:
Syfaro 2022-05-19 12:26:14 -04:00
parent 0850e4e682
commit 25c457d8dc
7 changed files with 289 additions and 284 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
/target **/target
.env .env

542
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -271,14 +271,13 @@ pub async fn search_file(
submission.file_id, submission.file_id,
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int,
artist.name, artist.name,
hashes.id hash_id array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags
FROM FROM
submission submission
JOIN artist JOIN artist
ON artist.id = submission.artist_id ON artist.id = submission.artist_id
JOIN hashes
ON hashes.furaffinity_id = submission.id
WHERE WHERE
file_id = $1 file_id = $1
LIMIT 10", LIMIT 10",
@ -293,14 +292,13 @@ pub async fn search_file(
submission.file_id, submission.file_id,
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int,
artist.name, artist.name,
hashes.id hash_id array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags
FROM FROM
submission submission
JOIN artist JOIN artist
ON artist.id = submission.artist_id ON artist.id = submission.artist_id
JOIN hashes
ON hashes.furaffinity_id = submission.id
WHERE WHERE
lower(filename) = lower($1) lower(filename) = lower($1)
LIMIT 10", LIMIT 10",
@ -315,14 +313,13 @@ pub async fn search_file(
submission.file_id, submission.file_id,
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int,
artist.name, artist.name,
hashes.id hash_id array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags
FROM FROM
submission submission
JOIN artist JOIN artist
ON artist.id = submission.artist_id ON artist.id = submission.artist_id
JOIN hashes
ON hashes.furaffinity_id = submission.id
WHERE WHERE
lower(url) = lower($1) lower(url) = lower($1)
LIMIT 10", LIMIT 10",
@ -337,14 +334,13 @@ pub async fn search_file(
submission.file_id, submission.file_id,
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int,
artist.name, artist.name,
hashes.id hash_id array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags
FROM FROM
submission submission
JOIN artist JOIN artist
ON artist.id = submission.artist_id ON artist.id = submission.artist_id
JOIN hashes
ON hashes.furaffinity_id = submission.id
WHERE WHERE
submission.id = $1 submission.id = $1
LIMIT 10", LIMIT 10",
@ -364,8 +360,9 @@ pub async fn search_file(
artists: row artists: row
.get::<Option<String>, _>("name") .get::<Option<String>, _>("name")
.map(|artist| vec![artist]), .map(|artist| vec![artist]),
tags: row.get("tags"),
distance: None, distance: None,
hash: None, hash: row.get::<Option<i64>, _>("hash_int"),
searched_hash: None, searched_hash: None,
site_info: Some(SiteInfo::FurAffinity { site_info: Some(SiteInfo::FurAffinity {
file_id: row.get("file_id"), file_id: row.get("file_id"),

View File

@ -173,6 +173,7 @@ pub async fn image_query(
site_id_str: row.id.unwrap_or_default().to_string(), site_id_str: row.id.unwrap_or_default().to_string(),
url: row.url.unwrap_or_default(), url: row.url.unwrap_or_default(),
posted_at: row.posted_at, posted_at: row.posted_at,
tags: None,
hash: row.hash, hash: row.hash,
distance: row distance: row
.distance .distance

View File

@ -36,6 +36,9 @@ pub struct SearchResult {
pub rating: Option<Rating>, pub rating: Option<Rating>,
pub posted_at: Option<chrono::DateTime<chrono::Utc>>, pub posted_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[serde(flatten)] #[serde(flatten)]
pub site_info: Option<SiteInfo>, pub site_info: Option<SiteInfo>,

View File

@ -0,0 +1 @@
DROP INDEX tag_to_post_post_id;

View File

@ -0,0 +1 @@
CREATE INDEX tag_to_post_post_id ON tag_to_post (post_id);