Skip to content

Commit a27db8b

Browse files
authored
Merge pull request #731 from thoth-pub/feature/fuzzy_isbn_search
Support searching for publications by unhyphenated ISBN
2 parents d5ef704 + d866868 commit a27db8b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- [#731](https://github.com/thoth-pub/thoth/pull/731) - Ignore hyphens when filtering publications on ISBN
810

911
## [[0.13.15]](https://github.com/thoth-pub/thoth/releases/tag/v0.13.15) - 2025-12-03
1012
### Changed

thoth-api/src/model/publication/crud.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ use super::{
33
PublicationHistory, PublicationOrderBy, PublicationType,
44
};
55
use crate::graphql::utils::Direction;
6-
use crate::model::{Crud, DbInsert, HistoryEntry};
6+
use crate::model::{Crud, DbInsert, HistoryEntry, Isbn};
77
use crate::schema::{publication, publication_history};
88
use crate::{crud_methods, db_insert};
9-
use diesel::{ExpressionMethods, PgTextExpressionMethods, QueryDsl, RunQueryDsl};
9+
use diesel::{
10+
dsl::sql, sql_types::Text, ExpressionMethods, PgTextExpressionMethods, QueryDsl, RunQueryDsl,
11+
};
1012
use thoth_errors::ThothResult;
1113
use uuid::Uuid;
1214

@@ -112,7 +114,11 @@ impl Crud for Publication {
112114
if let Some(filter) = filter {
113115
// ISBN field is nullable, so searching with an empty filter could fail
114116
if !filter.is_empty() {
115-
query = query.filter(isbn.ilike(format!("%{filter}%")));
117+
// Ignore ISBN hyphenation when searching
118+
query = query.filter(
119+
sql::<Text>("replace(isbn, '-', '')")
120+
.ilike(format!("%{}%", filter.replace("-", ""))),
121+
);
116122
}
117123
}
118124
query
@@ -144,7 +150,11 @@ impl Crud for Publication {
144150
if let Some(filter) = filter {
145151
// ISBN field is nullable, so searching with an empty filter could fail
146152
if !filter.is_empty() {
147-
query = query.filter(isbn.ilike(format!("%{filter}%")));
153+
// Ignore ISBN hyphenation when searching
154+
query = query.filter(
155+
sql::<Text>("replace(isbn, '-', '')")
156+
.ilike(format!("%{}%", filter.replace("-", ""))),
157+
);
148158
}
149159
}
150160

0 commit comments

Comments
 (0)