add null context for removing index from search clause

This commit is contained in:
Jörg Prante 2021-06-15 18:18:05 +02:00
parent f83ae36758
commit 81d29ef733
6 changed files with 23 additions and 15 deletions

View file

@ -16,13 +16,16 @@ public class Index extends AbstractNode {
}
public Index(String name) {
this.context = "";
this.name = name;
if (name != null) {
int pos = name.indexOf('.');
if (pos > 0) {
this.context = name.substring(0, pos);
this.name = name.substring(pos + 1);
}
}
}
public void setContext(String context) {
this.context = context;
@ -54,7 +57,6 @@ public class Index extends AbstractNode {
@Override
public String toString() {
return context != null ? context + "." + name : name;
return context != null && !context.isEmpty() ? context + "." + name : name;
}
}

View file

@ -53,10 +53,10 @@ public class SearchClause extends AbstractNode {
public String toString() {
return query != null && query.toString().length() > 0 ? "(" + query + ")"
: query != null ? ""
: index != null && index.getContext() == null && index.getName() == null && term != null ? term.toString()
: index != null && !CQLQueryModel.isVisible(index.getContext()) ? ""
: index != null ? index + " " + relation + " " + term
: term != null ? term.toString()
: "";
}
}

View file

@ -171,9 +171,10 @@ public final class CQLQueryModel {
* @return true if visible, false if not
*/
public static boolean isVisible(String context) {
return !isFacetContext(context)
&& !isFilterContext(context)
&& !isOptionContext(context);
return context != null &&
!isFacetContext(context) &&
!isFilterContext(context) &&
!isOptionContext(context);
}
/**

View file

@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -14,6 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
class QueryTest {
private static final Logger logger = Logger.getLogger(QueryTest.class.getName());
@Test
void testValidQueries() throws IOException {
test("queries.txt");
@ -37,14 +41,15 @@ class QueryTest {
}
ok++;
} catch (Exception e) {
logger.log(Level.WARNING, e.getMessage());
errors++;
}
count++;
}
}
lr.close();
assertEquals(errors, 0);
assertEquals(ok, count);
assertEquals(0, errors);
assertEquals(count, ok);
}
private void validate(String line) throws Exception {

View file

@ -393,7 +393,7 @@ public class ElasticsearchQueryGenerator implements Visitor {
@Override
public void visit(Index node) {
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));
esname.setType(model.getElasticsearchType(name));
stack.push(esname);

View file

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