thomasmueller commented on code in PR #2145:
URL: https://github.com/apache/jackrabbit-oak/pull/2145#discussion_r1984890867
##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/util/ElasticIndexUtils.java:
##########
@@ -31,6 +31,110 @@ public class ElasticIndexUtils {
private static final Logger LOG =
LoggerFactory.getLogger(ElasticIndexUtils.class);
+ /**
+ * Convert a JCR property name to a Elasticsearch field name.
+ * Notice that "|" is not allowed in JCR names.
+ *
+ * @param propertyName the property name
+ * @return the field name
+ */
+ public static String fieldName(String propertyName) {
+ if(propertyName.startsWith(":")) {
+ // there are some hardcoded field names
+ return propertyName;
+ }
+ String fieldName = propertyName;
+ boolean escape = false;
+ if (fieldName.isBlank()) {
+ // empty field name or field names that only consist of spaces
+ escape = true;
+ } else {
+ // 99.99% property names are OK,
+ // so we loop over the characters first
+ for (int i = 0; i < fieldName.length(); i++) {
+ switch (fieldName.charAt(i)) {
+ case '|':
+ case '.':
+ case '^':
+ case '_':
+ escape = true;
+ }
+ }
+ }
+ if (escape) {
+ StringBuilder buff = new StringBuilder(fieldName.length());
+ for (int i = 0; i < fieldName.length(); i++) {
+ char c = fieldName.charAt(i);
+ switch (c) {
+ case '|':
+ buff.append("||");
+ break;
+ case '.':
+ case '^':
+
buff.append('|').append(Integer.toHexString(c)).append('|');
Review Comment:
Yes, it's possible... but this is not on the critical path, and I wanted to
allow extending the list if needed... it's really hard to get a good list...
the `^` I found myself, and I first also had `#` and `-` and I'm not sure if
those never need to be escaped...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]