Include which hash caused a match in hashes.

This commit is contained in:
Syfaro 2020-02-19 00:40:43 -06:00
parent 904d3290e1
commit 68b8b911d2
4 changed files with 19 additions and 2 deletions

View File

@ -203,7 +203,13 @@ pub async fn search_hashes(
rate_limit!(&api_key, &db, image_limit, "image", hashes.len() as i16);
let mut results = image_query_sync(pool, tree, hashes.clone(), 10, None);
let mut results = image_query_sync(
pool,
tree,
hashes.clone(),
opts.distance.unwrap_or(10),
None,
);
let mut matches = Vec::new();
while let Some(r) = results.recv().await {
@ -275,6 +281,7 @@ pub async fn search_file(
site_info: Some(SiteInfo::FurAffinity(FurAffinityFile {
file_id: row.get("file_id"),
})),
searched_hash: None,
})
.collect();

View File

@ -130,7 +130,12 @@ pub fn image_query_sync(
LIMIT 1
) tm ON hashes.twitter_id IS NOT NULL
WHERE hashes.id = $1", &[&item.id]).await;
let rows = query.map(|rows| extract_rows(rows, hash.as_deref()).into_iter().collect());
let rows = query.map(|rows| {
extract_rows(rows, hash.as_deref()).into_iter().map(|mut file| {
file.searched_hash = Some(query_hash);
file
}).collect()
});
tx.send(rows).await.unwrap();
}
}

View File

@ -42,6 +42,9 @@ pub struct File {
pub hash: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub distance: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub searched_hash: Option<i64>,
}
#[derive(Debug, Serialize)]
@ -101,4 +104,5 @@ pub struct ErrorMessage {
#[derive(Debug, Deserialize)]
pub struct HashSearchOpts {
pub hashes: String,
pub distance: Option<i64>,
}

View File

@ -109,6 +109,7 @@ pub fn extract_rows<'a>(
.flatten(),
artists: row.get("artists"),
filename: row.get("filename"),
searched_hash: None,
}
})
}