From 1eaade145432649425c7c16d40283db9417d71aa Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 29 Oct 2024 16:06:27 +0100 Subject: [PATCH] Add `almaMmsId` and `zdbId` to IdQuery (#2085) --- web/app/controllers/resources/Queries.java | 11 ++++---- web/test/tests/IntegrationTests.java | 30 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/web/app/controllers/resources/Queries.java b/web/app/controllers/resources/Queries.java index a7c662fc7..211948760 100644 --- a/web/app/controllers/resources/Queries.java +++ b/web/app/controllers/resources/Queries.java @@ -412,7 +412,8 @@ private static boolean hasLabel(String queryString) { public static class IdQuery extends AbstractIndexQuery { @Override public List fields() { - return Arrays.asList("isbn", "issn", "hbzId", "rpbId", "schoeneNummer"); + return Arrays.asList("almaMmsId", "hbzId", "isbn", "issn", "rpbId", + "schoeneNummer", "zdbId"); } @Override @@ -424,11 +425,9 @@ public QueryBuilder build(final String queryString) { private static String normalizedLobidResourceIdQueryString( final String queryString) { String normalizedQueryString = queryString.replaceAll(" ", ""); - if (!normalizedQueryString.contains("/")) // thus: doi or isbn - if (normalizedQueryString.matches("\"?\\d.*\"?")) { // thus: isbn - normalizedQueryString = normalizedQueryString.replaceAll("-", ""); - } - return normalizedQueryString; + String withoutDashes = normalizedQueryString.replaceAll("-", ""); + return withoutDashes.matches("\\d{10}|\\d{13}") ? // ISBN + withoutDashes : normalizedQueryString; } } diff --git a/web/test/tests/IntegrationTests.java b/web/test/tests/IntegrationTests.java index b0495d3c0..dfa9b7a64 100644 --- a/web/test/tests/IntegrationTests.java +++ b/web/test/tests/IntegrationTests.java @@ -149,6 +149,36 @@ private static void ownerTest(String id) { }); } + @Test + public void sizeRequestIdAlmaMmsId() { + idTest("990053976760206441"); + } + + @Test + public void sizeRequestIdZdbId() { + idTest("123550-3"); + } + + @Test + public void sizeRequestIdIsbn10() { + idTest("0-40503-920-4"); + idTest("0405039204"); + } + + @Test + public void sizeRequestIdIsbn13() { + idTest("978-0-40503-920-1"); + idTest("9780405039201"); + } + + private static void idTest(String id) { + running(testServer(3333), () -> { + Search index = new Search.Builder() + .query(new Queries.Builder().id(id).build()).build(); + assertThat(index.totalHits()).isGreaterThan(0); + }); + } + @Test public void agentRequest() { running(testServer(3333), () -> {