new CQL default context

This commit is contained in:
Jörg Prante 2021-06-01 18:58:18 +02:00
parent 7475a5f565
commit 1a0ff7d6c8
6 changed files with 31 additions and 9 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = z3950 name = z3950
version = 2.3.0 version = 2.3.1
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 6.6.1
netty.version = 4.1.65.Final netty.version = 4.1.65.Final

View file

@ -53,6 +53,7 @@ public final class CQLRPNGenerator implements Visitor {
private static final long serialVersionUID = 8199395368653216950L; private static final long serialVersionUID = 8199395368653216950L;
{ {
put("default", ResourceBundle.getBundle("org.xbib.z3950.common.cql.default"));
put("cql", ResourceBundle.getBundle("org.xbib.z3950.common.cql.cql")); put("cql", ResourceBundle.getBundle("org.xbib.z3950.common.cql.cql"));
put("bib", ResourceBundle.getBundle("org.xbib.z3950.common.cql.bib-1")); put("bib", ResourceBundle.getBundle("org.xbib.z3950.common.cql.bib-1"));
put("dc", ResourceBundle.getBundle("org.xbib.z3950.common.cql.dc")); put("dc", ResourceBundle.getBundle("org.xbib.z3950.common.cql.dc"));
@ -67,13 +68,14 @@ public final class CQLRPNGenerator implements Visitor {
private RPNQuery rpnQuery; private RPNQuery rpnQuery;
public CQLRPNGenerator() { public CQLRPNGenerator() {
this.attributeElements = new Stack<>(); this(null);
this.result = new Stack<>();
} }
public CQLRPNGenerator(Collection<AttributeElement> attributeElements) { public CQLRPNGenerator(Collection<AttributeElement> attributeElements) {
this.attributeElements = new Stack<>(); this.attributeElements = new Stack<>();
this.attributeElements.addAll(attributeElements); if (attributeElements != null) {
this.attributeElements.addAll(attributeElements);
}
this.result = new Stack<>(); this.result = new Stack<>();
} }
@ -294,7 +296,7 @@ public final class CQLRPNGenerator implements Visitor {
public void visit(Index index) { public void visit(Index index) {
String context = index.getContext(); String context = index.getContext();
if (context == null) { if (context == null) {
context = "dc"; // default context context = "default"; // default context
} }
int attributeType = 1; // use attribute set: bib-1 = 1 int attributeType = 1; // use attribute set: bib-1 = 1
int attributeValue = getUseAttr(context, index.getName()); int attributeValue = getUseAttr(context, index.getName());

View file

@ -1,4 +1,5 @@
title=4 title=4
identifier=12 identifier=12
date=31 date=31
creator=1003
publisher=1018 publisher=1018

View file

@ -0,0 +1,16 @@
# Default properties
# this is a mashup of all common search keys
identifier=12
publisher=1018
all=1035
keywords=1016
title=4
date=31
creator=1003
format=1220
author=1003
intitle=5
isbn=7
issn=8
doi=1094
type=1031

View file

@ -22,7 +22,7 @@ class CQL2RPNTest {
} }
@Test @Test
void testPhrase() { void testPhraseWithDoubleQuotes() {
String cql = "dc.title = \"a phrase\""; String cql = "dc.title = \"a phrase\"";
CQLParser parser = new CQLParser(cql); CQLParser parser = new CQLParser(cql);
parser.parse(); parser.parse();
@ -33,15 +33,18 @@ class CQL2RPNTest {
} }
@Test @Test
void testWithAttribute() { void testWithOverridingAnAttribute() {
AttributeElement ae = new AttributeElement(); AttributeElement ae = new AttributeElement();
ae.attributeType = new ASN1Integer(2); ae.attributeType = new ASN1Integer(2);
ae.attributeValue = new AttributeElementAttributeValue();
ae.attributeValue.numeric = new ASN1Integer(4);
String cql = "dc.title = \"a phrase\""; String cql = "dc.title = \"a phrase\"";
CQLParser parser = new CQLParser(cql); CQLParser parser = new CQLParser(cql);
parser.parse(); parser.parse();
CQLRPNGenerator generator = new CQLRPNGenerator(Collections.singleton(ae)); CQLRPNGenerator generator = new CQLRPNGenerator(Collections.singleton(ae));
parser.getCQLQuery().accept(generator); parser.getCQLQuery().accept(generator);
String q = generator.getQueryResult().toString(); String q = generator.getQueryResult().toString();
assertEquals("{attributeSetId 1.2.840.10003.3.1, rpn {op {attrTerm {attributes {{attributeType 2, attributeValue {numeric 3}}{attributeType 4, attributeValue {numeric 1}}{attributeType 5, attributeValue {numeric 100}}{attributeType 1, attributeValue {numeric 4}}}, term {general \"a phrase\"}}}}}", q); // not really working, it adds, not override
assertEquals("{attributeSetId 1.2.840.10003.3.1, rpn {op {attrTerm {attributes {{attributeType 2, attributeValue {numeric 4}}{attributeType 2, attributeValue {numeric 3}}{attributeType 4, attributeValue {numeric 1}}{attributeType 5, attributeValue {numeric 100}}{attributeType 1, attributeValue {numeric 4}}}, term {general \"a phrase\"}}}}}", q);
} }
} }