update to content 3.0.0

This commit is contained in:
Jörg Prante 2021-05-27 16:30:35 +02:00
parent e951774a5d
commit f83ae36758
8 changed files with 54 additions and 30 deletions

View file

@ -28,7 +28,7 @@ subprojects {
apply from: rootProject.file('gradle/ide/idea.gradle')
apply from: rootProject.file('gradle/compile/java.gradle')
apply from: rootProject.file('gradle/test/junit5.gradle')
apply from: rootProject.file('gradle/repositories/maven.gradle')
apply from: rootProject.file('gradle/publishing/publication.gradle')
}
apply from: rootProject.file('gradle/publishing/sonatype.gradle')

View file

@ -1,4 +1,5 @@
dependencies {
api project(':cql-common')
api "org.xbib:content-core:${project.property('xbib-content.version')}"
implementation "org.xbib:content-core:${project.property('xbib-content.version')}"
implementation "org.xbib:content-json:${project.property('xbib-content.version')}"
}

View file

@ -3,5 +3,6 @@ module org.xbib.cql.elasticsearch {
exports org.xbib.cql.elasticsearch.ast;
exports org.xbib.cql.elasticsearch.model;
requires transitive org.xbib.cql;
requires transitive org.xbib.content.core;
requires org.xbib.content.core;
requires org.xbib.content.json;
}

View file

@ -1,6 +1,7 @@
package org.xbib.cql.elasticsearch;
import org.xbib.content.XContentBuilder;
import org.xbib.content.core.DefaultXContentBuilder;
import org.xbib.cql.BooleanGroup;
import org.xbib.cql.BooleanOperator;
import org.xbib.cql.CQLParser;
@ -158,7 +159,7 @@ public class ElasticsearchQueryGenerator implements Visitor {
}
if (model.hasFilter()) {
queryGen.startFiltered();
} else if (filterGenerator.getResult().bytes().length() > 0) {
} else if (filterGenerator.getResult().string().length() > 0) {
queryGen.startFiltered();
}
Node querynode = stack.pop();
@ -169,16 +170,18 @@ public class ElasticsearchQueryGenerator implements Visitor {
new Expression(Operator.EQUALS, new Name("cql.allIndexes"), querynode);
}
queryGen.visit((Expression) querynode);
if (model.hasFilter()) {
if (model.hasFilter() && model.getFilterExpression() != null) {
queryGen.end();
filterGen = new FilterGenerator(queryGen);
filterGen.startFilter();
filterGen.visit(model.getFilterExpression());
filterGen.endFilter();
queryGen.end();
} else if (filterGenerator.getResult().bytes().length() > 0) {
} else if (filterGenerator.getResult().string().length() > 0) {
queryGen.end();
queryGen.getResult().rawField("filter", filterGenerator.getResult().bytes().toBytes());
DefaultXContentBuilder contentBuilder = (DefaultXContentBuilder) filterGenerator.getResult();
byte[] b = contentBuilder.bytes().toBytes();
queryGen.getResult().rawField("filter", b, 0, b.length);
queryGen.endFiltered();
}
if (boostField != null) {

View file

@ -1,13 +1,11 @@
package org.xbib.cql.elasticsearch;
import org.xbib.content.XContentBuilder;
import org.xbib.content.core.DefaultXContentBuilder;
import org.xbib.content.json.JsonXContent;
import java.io.IOException;
/**
*
*/
public class SourceGenerator {
private final XContentBuilder builder;
@ -16,22 +14,27 @@ public class SourceGenerator {
this.builder = JsonXContent.contentBuilder();
}
public void build(QueryGenerator query,
int from, int size) throws IOException {
public void build(QueryGenerator query) throws IOException {
build(query, null, null, null, null);
}
public void build(QueryGenerator query, Integer from, Integer size) throws IOException {
build(query, from, size, null, null);
}
public void build(QueryGenerator query, int from, int size, XContentBuilder sort, XContentBuilder facets)
throws IOException {
public void build(QueryGenerator query, Integer from, Integer size,
XContentBuilder sort, XContentBuilder facets) throws IOException {
builder.startObject();
if (query != null) {
if (from != null) {
builder.field("from", from);
builder.field("size", size);
builder.rawField("query", query.getResult().bytes().toBytes());
if (sort != null && sort.bytes().length() > 0) {
builder.rawField("sort", sort.bytes().toBytes());
}
if (facets != null && facets.bytes().length() > 0) {
builder.rawField("aggregations", facets.bytes().toBytes());
if (size != null) {
builder.field("size", size);
}
copy(builder, "query", query.getResult());
copy(builder, "sort", sort);
copy(builder, "aggregations", facets);
}
builder.endObject();
builder.close();
@ -40,4 +43,14 @@ public class SourceGenerator {
public XContentBuilder getResult() {
return builder;
}
private void copy(XContentBuilder builder, String rawFieldName, XContentBuilder anotherBuilder) throws IOException {
if (anotherBuilder != null) {
DefaultXContentBuilder contentBuilder = (DefaultXContentBuilder) anotherBuilder;
if (contentBuilder.bytes().length() > 0) {
byte[] b = contentBuilder.bytes().toBytes();
builder.rawField(rawFieldName, b, 0, b.length);
}
}
}
}

View file

@ -1,6 +1,6 @@
group = org.xbib
name = cql
version = 3.0.5
version = 3.1.0
gradle.wrapper.version = 6.6.1
xbib-content.version = 2.6.4
xbib-content.version = 3.0.0

View file

@ -53,6 +53,7 @@ if (project.hasProperty("signing.keyId")) {
}
}
if (project.hasProperty("ossrhUsername")) {
nexusPublishing {
repositories {
sonatype {
@ -62,3 +63,4 @@ nexusPublishing {
}
}
}
}

View file

@ -0,0 +1,4 @@
repositories {
mavenLocal()
mavenCentral()
}