[office/tellico] src: OpenLibrary: add capitalized title searches
Robby Stephenson <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 3e8ded4bf78ebfa1a205bdbdadc7cefd558abc82 by Robby Stephenson.
Committed on 01/08/2026 at 15:44.
Pushed by rstephenson into branch 'master'.
OpenLibrary: add capitalized title searches
M +9 -1 src/fetch/openlibraryfetcher.cpp
M +15 -0 src/tests/openlibraryfetchertest.cpp
M +1 -0 src/tests/openlibraryfetchertest.h
https://invent.kde.org/office/tellico/-/commit/3e8ded4bf78ebfa1a205bdbdadc7cefd558abc82
diff --git a/src/fetch/openlibraryfetcher.cpp b/src/fetch/openlibraryfetcher.cpp
index 683aeef38..89f63b510 100644
--- a/src/fetch/openlibraryfetcher.cpp
+++ b/src/fetch/openlibraryfetcher.cpp
@@ -92,8 +92,16 @@ void OpenLibraryFetcher::search() {
searchTerms = FieldFormat::splitValue(request().value());
} else {
searchTerms += request().value();
+ // using the query API as we do is case-sensitive
+ // so for titles, add an extra search with capitalization fixed
+ if(request().key() == Title) {
+ const QString newTerm = FieldFormat::capitalize(request().value());
+ if(newTerm != request().value()) {
+ searchTerms += newTerm;
+ }
+ }
}
- foreach(const QString& searchTerm, searchTerms) {
+ for(const auto& searchTerm : std::as_const(searchTerms)) {
doSearch(searchTerm);
}
if(m_jobs.isEmpty()) {
diff --git a/src/tests/openlibraryfetchertest.cpp b/src/tests/openlibraryfetchertest.cpp
index 06f12de41..4ac86f94e 100644
--- a/src/tests/openlibraryfetchertest.cpp
+++ b/src/tests/openlibraryfetchertest.cpp
@@ -59,6 +59,21 @@ void OpenLibraryFetcherTest::testTitle() {
QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Barrayar"));
}
+// checking title case sensitivity
+void OpenLibraryFetcherTest::testTitle2() {
+ Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title,
+ QStringLiteral("some golden harbor"));
+ Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this));
+ QVERIFY(fetcher->canSearch(request.key()));
+
+ Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
+
+ QCOMPARE(results.size(), 1);
+
+ Tellico::Data::EntryPtr entry = results.at(0);
+ QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Some Golden Harbor"));
+}
+
void OpenLibraryFetcherTest::testAuthor() {
Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Person,
QStringLiteral("Bujold"));
diff --git a/src/tests/openlibraryfetchertest.h b/src/tests/openlibraryfetchertest.h
index 35fc8a1fe..6b935b9ff 100644
--- a/src/tests/openlibraryfetchertest.h
+++ b/src/tests/openlibraryfetchertest.h
@@ -35,6 +35,7 @@ public:
private Q_SLOTS:
void initTestCase();
void testTitle();
+ void testTitle2();
void testAuthor();
void testIsbn();
void testIsbn13();