From 27c06ac9449bdb21afb9f21ebf8ee86561b8fc1e Mon Sep 17 00:00:00 2001 From: Lolo Date: Fri, 20 Dec 2019 16:20:53 +0100 Subject: [PATCH] Simplify the filter check for opensearch Instead of checking each field, we can simply get a filter list of properties... --- .../arlas/server/utils/FilterMatcherUtil.java | 2 +- .../OpenSearchDescriptorService.java | 56 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/arlas-core/src/main/java/io/arlas/server/utils/FilterMatcherUtil.java b/arlas-core/src/main/java/io/arlas/server/utils/FilterMatcherUtil.java index d05cca63b..709444e05 100644 --- a/arlas-core/src/main/java/io/arlas/server/utils/FilterMatcherUtil.java +++ b/arlas-core/src/main/java/io/arlas/server/utils/FilterMatcherUtil.java @@ -36,7 +36,7 @@ public class FilterMatcherUtil { private static final Map PATTERN_COMPILED_CACHE = new HashMap<>(); private static final Pattern EMPTY_PATTERN = Pattern.compile(""); - //these are metacharacters, i.a. caracters that can be used within regexp. If present in filter: we escape them. Except the "star" that is a wildcard. + //these are metacharacters, i.a. characters that can be used within regexp. If present in filter: we escape them. Except the "star" that is a wildcard. private static final Map PREDICATE_REPLACE_CHAR = Arrays.asList("\\","^","$","{","}","[","]","(",")",".","+","?","|","<",">","-","&","%").stream() .collect(Collectors.toMap(c -> c, c -> "\\" + c)); static { diff --git a/arlas-opensearch/src/main/java/io/arlas/server/rest/explore/opensearch/OpenSearchDescriptorService.java b/arlas-opensearch/src/main/java/io/arlas/server/rest/explore/opensearch/OpenSearchDescriptorService.java index 19e57df16..6c85ed486 100644 --- a/arlas-opensearch/src/main/java/io/arlas/server/rest/explore/opensearch/OpenSearchDescriptorService.java +++ b/arlas-opensearch/src/main/java/io/arlas/server/rest/explore/opensearch/OpenSearchDescriptorService.java @@ -135,7 +135,7 @@ public Response opensearch( description.tags = os.tags; } Optional> columnFilterPredicates = ColumnFilterUtil.getColumnFilterPredicates(columnFilter, cr); - addURLs(prefix, description.url, admin.describeCollection(cr).properties, new Stack<>(), columnFilterPredicates); + addURLs(prefix, description.url, admin.describeCollection(cr, columnFilter).properties, new Stack<>()); List urls = new ArrayList<>(); description.url.forEach(url -> { urls.add(url(url.template + "&gintersect={geo:box?}")); @@ -145,7 +145,7 @@ public Response opensearch( return cache(Response.ok(description), maxagecache); } - private void addURLs(String templatePrefix, List urls, Map properties, Stack namespace, Optional> columnFilterPredicates) { + private void addURLs(String templatePrefix, List urls, Map properties, Stack namespace) { if (properties == null) { return; } @@ -153,35 +153,33 @@ private void addURLs(String templatePrefix, List urls, Map(namespace)); - if (FilterMatcherUtil.matches(columnFilterPredicates, fieldPath)) { - switch (property.type) { - case DATE: - addNumberUrls(urls, templatePrefix, fieldPath, "long"); - break; - case LONG: - addNumberUrls(urls, templatePrefix, fieldPath, "long"); - break; - case DOUBLE: - addNumberUrls(urls, templatePrefix, fieldPath, "double"); - case FLOAT: - addNumberUrls(urls, templatePrefix, fieldPath, "float"); - case SHORT: - addNumberUrls(urls, templatePrefix, fieldPath, "short"); - break; - case INTEGER: - addNumberUrls(urls, templatePrefix, fieldPath, "integer"); - break; - case TEXT: - urls.add(url(templatePrefix + "?f=" + fieldPath + ":eq:{text?}")); - urls.add(url(templatePrefix + "?f=" + fieldPath + ":like:{text?}")); - break; - case KEYWORD: - urls.add(url(templatePrefix + "?f=" + fieldPath + ":eq:{text?}")); - break; - } + switch (property.type) { + case DATE: + addNumberUrls(urls, templatePrefix, fieldPath, "long"); + break; + case LONG: + addNumberUrls(urls, templatePrefix, fieldPath, "long"); + break; + case DOUBLE: + addNumberUrls(urls, templatePrefix, fieldPath, "double"); + case FLOAT: + addNumberUrls(urls, templatePrefix, fieldPath, "float"); + case SHORT: + addNumberUrls(urls, templatePrefix, fieldPath, "short"); + break; + case INTEGER: + addNumberUrls(urls, templatePrefix, fieldPath, "integer"); + break; + case TEXT: + urls.add(url(templatePrefix + "?f=" + fieldPath + ":eq:{text?}")); + urls.add(url(templatePrefix + "?f=" + fieldPath + ":like:{text?}")); + break; + case KEYWORD: + urls.add(url(templatePrefix + "?f=" + fieldPath + ":eq:{text?}")); + break; } } namespace.pop();