add null context for removing index from search clause
This commit is contained in:
parent
f83ae36758
commit
81d29ef733
6 changed files with 23 additions and 15 deletions
|
@ -16,13 +16,16 @@ public class Index extends AbstractNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Index(String name) {
|
public Index(String name) {
|
||||||
|
this.context = "";
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
if (name != null) {
|
||||||
int pos = name.indexOf('.');
|
int pos = name.indexOf('.');
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
this.context = name.substring(0, pos);
|
this.context = name.substring(0, pos);
|
||||||
this.name = name.substring(pos + 1);
|
this.name = name.substring(pos + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setContext(String context) {
|
public void setContext(String context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -54,7 +57,6 @@ public class Index extends AbstractNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return context != null ? context + "." + name : name;
|
return context != null && !context.isEmpty() ? context + "." + name : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,10 @@ public class SearchClause extends AbstractNode {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return query != null && query.toString().length() > 0 ? "(" + query + ")"
|
return query != null && query.toString().length() > 0 ? "(" + query + ")"
|
||||||
: query != null ? ""
|
: query != null ? ""
|
||||||
|
: index != null && index.getContext() == null && index.getName() == null && term != null ? term.toString()
|
||||||
: index != null && !CQLQueryModel.isVisible(index.getContext()) ? ""
|
: index != null && !CQLQueryModel.isVisible(index.getContext()) ? ""
|
||||||
: index != null ? index + " " + relation + " " + term
|
: index != null ? index + " " + relation + " " + term
|
||||||
: term != null ? term.toString()
|
: term != null ? term.toString()
|
||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,9 +171,10 @@ public final class CQLQueryModel {
|
||||||
* @return true if visible, false if not
|
* @return true if visible, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isVisible(String context) {
|
public static boolean isVisible(String context) {
|
||||||
return !isFacetContext(context)
|
return context != null &&
|
||||||
&& !isFilterContext(context)
|
!isFacetContext(context) &&
|
||||||
&& !isOptionContext(context);
|
!isFilterContext(context) &&
|
||||||
|
!isOptionContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,6 +6,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
@ -14,6 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
*/
|
*/
|
||||||
class QueryTest {
|
class QueryTest {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(QueryTest.class.getName());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValidQueries() throws IOException {
|
void testValidQueries() throws IOException {
|
||||||
test("queries.txt");
|
test("queries.txt");
|
||||||
|
@ -37,14 +41,15 @@ class QueryTest {
|
||||||
}
|
}
|
||||||
ok++;
|
ok++;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.WARNING, e.getMessage());
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lr.close();
|
lr.close();
|
||||||
assertEquals(errors, 0);
|
assertEquals(0, errors);
|
||||||
assertEquals(ok, count);
|
assertEquals(count, ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate(String line) throws Exception {
|
private void validate(String line) throws Exception {
|
||||||
|
|
|
@ -393,7 +393,7 @@ public class ElasticsearchQueryGenerator implements Visitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(Index node) {
|
public void visit(Index node) {
|
||||||
String context = node.getContext();
|
String context = node.getContext();
|
||||||
String name = context != null ? context + "." + node.getName() : node.getName();
|
String name = context != null && !context.isEmpty() ? context + "." + node.getName() : node.getName();
|
||||||
Name esname = new Name(name, model.getVisibility(context));
|
Name esname = new Name(name, model.getVisibility(context));
|
||||||
esname.setType(model.getElasticsearchType(name));
|
esname.setType(model.getElasticsearchType(name));
|
||||||
stack.push(esname);
|
stack.push(esname);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = cql
|
name = cql
|
||||||
version = 3.1.0
|
version = 3.1.1
|
||||||
|
|
||||||
gradle.wrapper.version = 6.6.1
|
gradle.wrapper.version = 6.6.1
|
||||||
xbib-content.version = 3.0.0
|
xbib-content.version = 3.0.0
|
||||||
|
|
Loading…
Reference in a new issue