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,11 +16,14 @@ public class Index extends AbstractNode {
|
|||
}
|
||||
|
||||
public Index(String name) {
|
||||
this.context = "";
|
||||
this.name = name;
|
||||
int pos = name.indexOf('.');
|
||||
if (pos > 0) {
|
||||
this.context = name.substring(0, pos);
|
||||
this.name = name.substring(pos + 1);
|
||||
if (name != null) {
|
||||
int pos = name.indexOf('.');
|
||||
if (pos > 0) {
|
||||
this.context = name.substring(0, pos);
|
||||
this.name = name.substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
: "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -165,15 +165,16 @@ public final class CQLQueryModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get query of a given context.
|
||||
* Get query of a given context.
|
||||
*
|
||||
* @param context the context
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue