Skip to content

fix- exactly same video_id and video_hash #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ impl VideoHashIndex {
Ok(())
}

pub fn has_exact_match(
&self,
video_id: &str,
hash: &VideoHash,
) -> Result<bool, Box<dyn Error + Send + Sync>> {
let hash_value = binary_string_to_u64(&hash.hash)?;

let hashes = self.hashes.read().unwrap();
if let Some(&existing_hash) = hashes.get(video_id) {
return Ok(existing_hash == hash_value);
}

Ok(false)
}

fn ensure_index_built(&self) -> Result<(), Box<dyn Error + Send + Sync>> {
let mut index_lock = self.index.write().unwrap();

Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ pub async fn search(
}
};

let has_exact_match = match index.has_exact_match(&req.video_id, &query_hash) {
Ok(exists) => exists,
Err(e) => {
return HttpResponse::InternalServerError().json(ErrorResponse {
error: format!("Failed to check for exact match: {}", e),
});
}
};

if has_exact_match {
return HttpResponse::Ok().json(SearchResponse {
match_found: false,
match_details: None,
hash_added: false,
});
}

// Continue with the existing similarity search logic
let similar_hashes = match index.find_within_distance(&query_hash, MAX_HAMMING_DISTANCE) {
Ok(results) => results,
Err(e) => {
Expand Down