Skip to content

Commit

Permalink
Merge pull request #574 from gisaia/fix/column-filter-simplify-opense…
Browse files Browse the repository at this point in the history
…arch

Simplify the filter check for opensearch
  • Loading branch information
laurent-thiebaud-gisaia authored Dec 20, 2019
2 parents b238644 + 27c06ac commit b307b59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FilterMatcherUtil {
private static final Map<String, Pattern> 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<String, String> PREDICATE_REPLACE_CHAR = Arrays.asList("\\","^","$","{","}","[","]","(",")",".","+","?","|","<",">","-","&","%").stream()
.collect(Collectors.toMap(c -> c, c -> "\\" + c));
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Response opensearch(
description.tags = os.tags;
}
Optional<Set<String>> 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<Url> urls = new ArrayList<>();
description.url.forEach(url -> {
urls.add(url(url.template + "&gintersect={geo:box?}"));
Expand All @@ -145,43 +145,41 @@ public Response opensearch(
return cache(Response.ok(description), maxagecache);
}

private void addURLs(String templatePrefix, List<Url> urls, Map<String, CollectionReferenceDescriptionProperty> properties, Stack<String> namespace, Optional<Set<String>> columnFilterPredicates) {
private void addURLs(String templatePrefix, List<Url> urls, Map<String, CollectionReferenceDescriptionProperty> properties, Stack<String> namespace) {
if (properties == null) {
return;
}
for (String key : properties.keySet()) {
CollectionReferenceDescriptionProperty property = properties.get(key);
namespace.push(key);
if (property.type == ElasticType.OBJECT) {
addURLs(templatePrefix, urls, property.properties, namespace, columnFilterPredicates);
addURLs(templatePrefix, urls, property.properties, namespace);
} else {
String fieldPath = String.join(".", new ArrayList<>(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();
Expand Down

0 comments on commit b307b59

Please sign in to comment.