update to content 3.0.0
This commit is contained in:
parent
e951774a5d
commit
f83ae36758
8 changed files with 54 additions and 30 deletions
|
@ -28,7 +28,7 @@ subprojects {
|
||||||
apply from: rootProject.file('gradle/ide/idea.gradle')
|
apply from: rootProject.file('gradle/ide/idea.gradle')
|
||||||
apply from: rootProject.file('gradle/compile/java.gradle')
|
apply from: rootProject.file('gradle/compile/java.gradle')
|
||||||
apply from: rootProject.file('gradle/test/junit5.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/publication.gradle')
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: rootProject.file('gradle/publishing/sonatype.gradle')
|
apply from: rootProject.file('gradle/publishing/sonatype.gradle')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(':cql-common')
|
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')}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,6 @@ module org.xbib.cql.elasticsearch {
|
||||||
exports org.xbib.cql.elasticsearch.ast;
|
exports org.xbib.cql.elasticsearch.ast;
|
||||||
exports org.xbib.cql.elasticsearch.model;
|
exports org.xbib.cql.elasticsearch.model;
|
||||||
requires transitive org.xbib.cql;
|
requires transitive org.xbib.cql;
|
||||||
requires transitive org.xbib.content.core;
|
requires org.xbib.content.core;
|
||||||
|
requires org.xbib.content.json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.xbib.cql.elasticsearch;
|
package org.xbib.cql.elasticsearch;
|
||||||
|
|
||||||
import org.xbib.content.XContentBuilder;
|
import org.xbib.content.XContentBuilder;
|
||||||
|
import org.xbib.content.core.DefaultXContentBuilder;
|
||||||
import org.xbib.cql.BooleanGroup;
|
import org.xbib.cql.BooleanGroup;
|
||||||
import org.xbib.cql.BooleanOperator;
|
import org.xbib.cql.BooleanOperator;
|
||||||
import org.xbib.cql.CQLParser;
|
import org.xbib.cql.CQLParser;
|
||||||
|
@ -158,7 +159,7 @@ public class ElasticsearchQueryGenerator implements Visitor {
|
||||||
}
|
}
|
||||||
if (model.hasFilter()) {
|
if (model.hasFilter()) {
|
||||||
queryGen.startFiltered();
|
queryGen.startFiltered();
|
||||||
} else if (filterGenerator.getResult().bytes().length() > 0) {
|
} else if (filterGenerator.getResult().string().length() > 0) {
|
||||||
queryGen.startFiltered();
|
queryGen.startFiltered();
|
||||||
}
|
}
|
||||||
Node querynode = stack.pop();
|
Node querynode = stack.pop();
|
||||||
|
@ -169,16 +170,18 @@ public class ElasticsearchQueryGenerator implements Visitor {
|
||||||
new Expression(Operator.EQUALS, new Name("cql.allIndexes"), querynode);
|
new Expression(Operator.EQUALS, new Name("cql.allIndexes"), querynode);
|
||||||
}
|
}
|
||||||
queryGen.visit((Expression) querynode);
|
queryGen.visit((Expression) querynode);
|
||||||
if (model.hasFilter()) {
|
if (model.hasFilter() && model.getFilterExpression() != null) {
|
||||||
queryGen.end();
|
queryGen.end();
|
||||||
filterGen = new FilterGenerator(queryGen);
|
filterGen = new FilterGenerator(queryGen);
|
||||||
filterGen.startFilter();
|
filterGen.startFilter();
|
||||||
filterGen.visit(model.getFilterExpression());
|
filterGen.visit(model.getFilterExpression());
|
||||||
filterGen.endFilter();
|
filterGen.endFilter();
|
||||||
queryGen.end();
|
queryGen.end();
|
||||||
} else if (filterGenerator.getResult().bytes().length() > 0) {
|
} else if (filterGenerator.getResult().string().length() > 0) {
|
||||||
queryGen.end();
|
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();
|
queryGen.endFiltered();
|
||||||
}
|
}
|
||||||
if (boostField != null) {
|
if (boostField != null) {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package org.xbib.cql.elasticsearch;
|
package org.xbib.cql.elasticsearch;
|
||||||
|
|
||||||
import org.xbib.content.XContentBuilder;
|
import org.xbib.content.XContentBuilder;
|
||||||
|
import org.xbib.content.core.DefaultXContentBuilder;
|
||||||
import org.xbib.content.json.JsonXContent;
|
import org.xbib.content.json.JsonXContent;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SourceGenerator {
|
public class SourceGenerator {
|
||||||
|
|
||||||
private final XContentBuilder builder;
|
private final XContentBuilder builder;
|
||||||
|
@ -16,22 +14,27 @@ public class SourceGenerator {
|
||||||
this.builder = JsonXContent.contentBuilder();
|
this.builder = JsonXContent.contentBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build(QueryGenerator query,
|
public void build(QueryGenerator query) throws IOException {
|
||||||
int from, int size) 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);
|
build(query, from, size, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build(QueryGenerator query, int from, int size, XContentBuilder sort, XContentBuilder facets)
|
public void build(QueryGenerator query, Integer from, Integer size,
|
||||||
throws IOException {
|
XContentBuilder sort, XContentBuilder facets) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field("from", from);
|
if (query != null) {
|
||||||
builder.field("size", size);
|
if (from != null) {
|
||||||
builder.rawField("query", query.getResult().bytes().toBytes());
|
builder.field("from", from);
|
||||||
if (sort != null && sort.bytes().length() > 0) {
|
}
|
||||||
builder.rawField("sort", sort.bytes().toBytes());
|
if (size != null) {
|
||||||
}
|
builder.field("size", size);
|
||||||
if (facets != null && facets.bytes().length() > 0) {
|
}
|
||||||
builder.rawField("aggregations", facets.bytes().toBytes());
|
copy(builder, "query", query.getResult());
|
||||||
|
copy(builder, "sort", sort);
|
||||||
|
copy(builder, "aggregations", facets);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.close();
|
builder.close();
|
||||||
|
@ -40,4 +43,14 @@ public class SourceGenerator {
|
||||||
public XContentBuilder getResult() {
|
public XContentBuilder getResult() {
|
||||||
return builder;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = cql
|
name = cql
|
||||||
version = 3.0.5
|
version = 3.1.0
|
||||||
|
|
||||||
gradle.wrapper.version = 6.6.1
|
gradle.wrapper.version = 6.6.1
|
||||||
xbib-content.version = 2.6.4
|
xbib-content.version = 3.0.0
|
||||||
|
|
|
@ -53,12 +53,14 @@ if (project.hasProperty("signing.keyId")) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nexusPublishing {
|
if (project.hasProperty("ossrhUsername")) {
|
||||||
repositories {
|
nexusPublishing {
|
||||||
sonatype {
|
repositories {
|
||||||
username = project.property('ossrhUsername')
|
sonatype {
|
||||||
password = project.property('ossrhPassword')
|
username = project.property('ossrhUsername')
|
||||||
packageGroup = "org.xbib"
|
password = project.property('ossrhPassword')
|
||||||
|
packageGroup = "org.xbib"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
gradle/repositories/maven.gradle
Normal file
4
gradle/repositories/maven.gradle
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
Loading…
Reference in a new issue