Skip to content

Commit

Permalink
Merge #2086 from remote-tracking branch 'origin/2085-idQuery'
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed Oct 31, 2024
2 parents 7b5b8e9 + 1eaade1 commit 3fa34f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
11 changes: 5 additions & 6 deletions web/app/controllers/resources/Queries.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ private static boolean hasLabel(String queryString) {
public static class IdQuery extends AbstractIndexQuery {
@Override
public List<String> fields() {
return Arrays.asList("isbn", "issn", "hbzId", "rpbId", "schoeneNummer");
return Arrays.asList("almaMmsId", "hbzId", "isbn", "issn", "rpbId",
"schoeneNummer", "zdbId");
}

@Override
Expand All @@ -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;
}
}

Expand Down
30 changes: 30 additions & 0 deletions web/test/tests/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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), () -> {
Expand Down

0 comments on commit 3fa34f8

Please sign in to comment.