diff --git a/gradle.properties b/gradle.properties index 7f23f94..fecf301 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.xbib name = z3950 -version = 5.1.5 +version = 5.1.6 org.gradle.warning.mode = ALL diff --git a/z3950-client-jdk/src/main/java/org/xbib/z3950/client/jdk/JDKZClient.java b/z3950-client-jdk/src/main/java/org/xbib/z3950/client/jdk/JDKZClient.java index 63f8f9b..0e20176 100644 --- a/z3950-client-jdk/src/main/java/org/xbib/z3950/client/jdk/JDKZClient.java +++ b/z3950-client-jdk/src/main/java/org/xbib/z3950/client/jdk/JDKZClient.java @@ -72,7 +72,7 @@ public class JDKZClient implements Client, Closeable { lock.lock(); SearchOperation searchOperation = new SearchOperation(berReader, berWriter, builder.resultSetName, builder.databases, builder.host); - boolean success = searchOperation.executeCQL(query); + boolean success = searchOperation.executeCQL(query, builder.wordListSupported); if (!success) { logger.log(Level.WARNING, MessageFormat.format("search was not a success [{0}]", query)); } else { @@ -410,6 +410,8 @@ public class JDKZClient implements Client, Closeable { private InitListener initListener; + private boolean wordListSupported; + private Builder() { this.timeout = 5000; this.preferredRecordSyntax = "1.2.840.10003.5.10"; // marc21 @@ -421,6 +423,7 @@ public class JDKZClient implements Client, Closeable { this.preferredMessageSize = 10 * 1024 * 1024; this.implementationName = "Java Z Client"; this.implementationVersion = "1.00"; + this.wordListSupported = true; } public Builder setHost(String host) { @@ -506,6 +509,11 @@ public class JDKZClient implements Client, Closeable { return this; } + public Builder wordListSupported(boolean wordListSupported) { + this.wordListSupported = wordListSupported; + return this; + } + public JDKZClient build() { return new JDKZClient(this); } diff --git a/z3950-client-jdk/src/test/java/org/xbib/z3950/client/jdk/test/SWBClientTest.java b/z3950-client-jdk/src/test/java/org/xbib/z3950/client/jdk/test/SWBClientTest.java index 164fe0e..9eafdeb 100644 --- a/z3950-client-jdk/src/test/java/org/xbib/z3950/client/jdk/test/SWBClientTest.java +++ b/z3950-client-jdk/src/test/java/org/xbib/z3950/client/jdk/test/SWBClientTest.java @@ -1,10 +1,7 @@ package org.xbib.z3950.client.jdk.test; -import java.io.IOException; -import java.io.InputStream; import java.nio.charset.Charset; import java.util.Collections; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.junit.jupiter.api.Test; @@ -16,15 +13,14 @@ class SWBClientTest { @Test void testCQL() { - String serviceName = "SWB"; - String query = "bib.identifierISSN = 00280836"; + //String query = "bib.identifierISSN = 00280836"; + String query = "bib.any all test"; int from = 1; int size = 10; - try (JDKZClient client = newZClient(serviceName)) { - logger.log(Level.INFO, "executing CQL " + serviceName); + try (JDKZClient client = newZClient()) { int count = client.searchCQL(query, from, size, null, (status, total, returned, elapsedMillis) -> - logger.log(Level.INFO, serviceName + " total results = " + total), + logger.log(Level.INFO, "total results = " + total), record -> logger.log(Level.INFO, "record = " + record), () -> logger.log(Level.INFO, "timeout")); logger.log(Level.INFO, "returned records = " + count); @@ -35,15 +31,13 @@ class SWBClientTest { @Test void testPQF() { - String serviceName = "SWB"; String query = "@attr 1=8 \"00280836\""; int from = 1; int size = 10; - try (JDKZClient client = newZClient(serviceName)) { - logger.log(Level.INFO, "executing PQF " + serviceName); + try (JDKZClient client = newZClient()) { int count = client.searchPQF(query, from, size, null, (status, total, returned, elapsedMillis) -> - logger.log(Level.INFO, serviceName + " status = " + status + " total results = " + total), + logger.log(Level.INFO, "status = " + status + " total results = " + total), record -> logger.log(Level.INFO, "record = " + record.toString(Charset.forName(client.getEncoding()))), () -> logger.log(Level.WARNING, "timeout")); logger.log(Level.INFO, "returned records = " + count); @@ -52,53 +46,19 @@ class SWBClientTest { } } - private JDKZClient newZClient(String name) throws IOException { - return newZClient(getProperties(name)); - } - - private Properties getProperties(String name) throws IOException { - Properties properties = new Properties(); - try (InputStream inputStream = getClass().getResourceAsStream(name + ".properties")) { - properties.load(inputStream); - } - return properties; - } - - private static JDKZClient newZClient(Properties properties) { - JDKZClient.Builder builder = JDKZClient.builder(); - if (properties.containsKey("host")) { - builder.setHost(properties.getProperty("host")); - } - if (properties.containsKey("port")) { - builder.setPort(Integer.parseInt(properties.getProperty("port"))); - } - if (properties.containsKey("user")) { - builder.setUser(properties.getProperty("user")); - } - if (properties.containsKey("pass")) { - builder.setPass(properties.getProperty("pass")); - } - if (properties.containsKey("database")) { - builder.setDatabases(Collections.singletonList(properties.getProperty("database"))); - } - if (properties.containsKey("elementsetname")) { - builder.setElementSetName(properties.getProperty("elementsetname")); - } - if (properties.containsKey("preferredrecordsyntax")) { - builder.setPreferredRecordSyntax(properties.getProperty("preferredrecordsyntax")); - } - if (properties.containsKey("resultsetname")) { - builder.setResultSetName(properties.getProperty("resultsetname")); - } - if (properties.containsKey("encoding")) { - builder.setEncoding(properties.getProperty("encoding")); - } - if (properties.containsKey("format")) { - builder.setFormat(properties.getProperty("format")); - } - if (properties.containsKey("type")) { - builder.setType(properties.getProperty("type")); - } + private JDKZClient newZClient() { + JDKZClient.Builder builder = JDKZClient.builder() + .setHost("z3950.bsz-bw.de") + .setPort(20210) + .setTimeout(10000L) + .setDatabases(Collections.singletonList("swb_fl")) + .setElementSetName("xf") + .setPreferredRecordSyntax("marc21") + .setResultSetName("default") + .setEncoding("UTF-8") + .setFormat("Marc21") + .setType("Bibliographic") + .wordListSupported(false); return builder.build(); } } diff --git a/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java b/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java index 436b903..0176c7c 100644 --- a/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java +++ b/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java @@ -57,11 +57,13 @@ public final class CQLRPNGenerator implements Visitor { private RPNQuery rpnQuery; + private final boolean wordListSupported; + public CQLRPNGenerator() { - this(null); + this(null, true); } - public CQLRPNGenerator(Collection attributeElements) { + public CQLRPNGenerator(Collection attributeElements, boolean wordListSupported) { this.attributeElements = new Stack<>(); if (attributeElements != null) { this.attributeElements.addAll(attributeElements); @@ -74,6 +76,7 @@ public final class CQLRPNGenerator implements Visitor { addContext("bib", ResourceBundle.getBundle("org.xbib.z3950.common.cql.bib-1")); addContext("dc", ResourceBundle.getBundle("org.xbib.z3950.common.cql.dc")); addContext("gbv", ResourceBundle.getBundle("org.xbib.z3950.common.cql.gbv")); + this.wordListSupported = wordListSupported; } public void addContext(String context, ResourceBundle bundle) { @@ -233,13 +236,11 @@ public final class CQLRPNGenerator implements Visitor { push(attributeElements, createAttributeElement(2, 5)); case NOT_EQUALS -> push(attributeElements, createAttributeElement(2, 6)); - case ALL -> { // 4=6 word list + case ALL, ANY -> { // 4=6 word list push(attributeElements, createAttributeElement(2, 3)); - replace(attributeElements, createAttributeElement(4, 6)); - } - case ANY -> { // 4=104 - push(attributeElements, createAttributeElement(2, 3)); - replace(attributeElements, createAttributeElement(4, 104)); + if (wordListSupported) { + replace(attributeElements, createAttributeElement(4, 6)); + } } default -> { } diff --git a/z3950-common/src/main/java/org/xbib/z3950/common/operations/SearchOperation.java b/z3950-common/src/main/java/org/xbib/z3950/common/operations/SearchOperation.java index e5da927..ed6b2cd 100644 --- a/z3950-common/src/main/java/org/xbib/z3950/common/operations/SearchOperation.java +++ b/z3950-common/src/main/java/org/xbib/z3950/common/operations/SearchOperation.java @@ -58,8 +58,8 @@ public class SearchOperation extends AbstractOperation