Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11837

Align index definition generation logic with the one from Oak

    XMLWordPrintableJSON

Details

    Description

      The logic used to generate the "str:" prefix for string values comes from here: https://github.com/apache/sling-org-apache-sling-feature-cpconverter/blob/a98317ba836d9acedb334518a438f4bcc8ce721d/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java#L108

      For prefixes, we should probably use the logic used in Oak. AFAIK this is implemented in https://github.com/apache/jackrabbit-oak/blob/838780a7aaf9775ad0bf7b6be65c1a1619e65eb7/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java#L269-L291:

          public void serialize(PropertyState property, Type<?> type, int index) {
              if (type == BOOLEAN) {
                  json.value(property.getValue(BOOLEAN, index));
              } else if (type == LONG) {
                  json.value(property.getValue(LONG, index));
              } else if (type == DOUBLE) {
                  Double value = property.getValue(DOUBLE, index);
                  if (value.isNaN() || value.isInfinite()) {
                      json.value(TypeCodes.encode(type.tag(), value.toString()));
                  } else {
                      json.encodedValue(value.toString());
                  }
              } else if (type == BINARY) {
                  Blob blob = property.getValue(BINARY, index);
                  json.value(TypeCodes.encode(type.tag(), blobs.serialize(blob)));
              } else  {
                  String value = property.getValue(STRING, index);
                  if (type != STRING || TypeCodes.split(value) != -1) {
                      value = TypeCodes.encode(type.tag(), value);
                  }
                  json.value(value);
              }
          }
      
          public static int split(String jsonString) {
              if (jsonString.startsWith(":blobId:")) {  // See OAK-428
                  return 7;
              }
              else if (jsonString.length() >= 4 && jsonString.charAt(3) == ':') {
                  return 3;
              }
              else {
                  return -1;
              }
          }
      
      

      So basically, the logic for String types is: if there is a ':' at position 4, then the "str:" prefix is needed. Otherwise, not. Note that we can't reuse the code since it uses the NodeState/PropertyState API.

      Attachments

        Issue Links

          Activity

            People

              rombert Robert Munteanu
              rombert Robert Munteanu
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: