Skip to content

Commit a046c1a

Browse files
authored
Merge pull request #59 from evolvedbinary/7.x.x/hotfix/lucene-field-string-type
[7.x.x] Allow Strings that contain entities to be correctly stored in Lucene fields
2 parents 4e4d25b + f485e9f commit a046c1a

File tree

4 files changed

+120
-85
lines changed

4 files changed

+120
-85
lines changed

exist-core/src/main/java/org/exist/xquery/value/StringValue.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,20 @@ public void serialize(final ByteBuffer buf) throws IOException {
890890
* @return the StringValue.
891891
*/
892892
public static StringValue deserialize(@Nullable final Expression expression, final ByteBuffer buf) throws IOException, XPathException {
893-
return deserialize(expression, buf, null);
893+
return deserialize(expression, buf, false);
894+
}
895+
896+
/**
897+
* Deserializes from a ByteBuffer.
898+
*
899+
* @param expression the expression that creates the StringValue object.
900+
* @param buf the ByteBuffer to deserialize from.
901+
* @param expand if entities need to be expanded
902+
*
903+
* @return the StringValue.
904+
*/
905+
public static StringValue deserialize(@Nullable final Expression expression, final ByteBuffer buf, final boolean expand) throws IOException, XPathException {
906+
return deserialize(expression, buf, null, expand);
894907
}
895908

896909
/**
@@ -903,12 +916,26 @@ public static StringValue deserialize(@Nullable final Expression expression, fin
903916
* @return the StringValue.
904917
*/
905918
public static StringValue deserialize(@Nullable Expression expression, final ByteBuffer buf, @Nullable final Integer checkType) throws IOException, XPathException {
919+
return deserialize(expression, buf, checkType, false);
920+
}
921+
922+
/**
923+
* Deserializes from a ByteBuffer.
924+
*
925+
* @param expression the expression that creates the StringValue object.
926+
* @param buf the ByteBuffer to deserialize from.
927+
* @param checkType an XDM type to check that matches against the deserialized StringValue type.
928+
* @param expand if entities need to be expanded
929+
*
930+
* @return the StringValue.
931+
*/
932+
public static StringValue deserialize(@Nullable Expression expression, final ByteBuffer buf, @Nullable final Integer checkType, final boolean expand) throws IOException, XPathException {
906933
final VariableByteBufferInput vbbi = new VariableByteBufferInput(buf);
907934
final int type = vbbi.read();
908935
if (checkType != null && type != checkType.intValue()) {
909936
throw new XPathException(expression, "Expected deserialized StringValue of type: " + Type.getTypeName(checkType) + ", but found: " + Type.getTypeName(type));
910937
}
911938
final String value = vbbi.readUTF();
912-
return new StringValue(expression, value, type);
939+
return new StringValue(expression, value, type, expand);
913940
}
914941
}

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/LuceneFieldConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ protected void processText(final NodeId nodeId, final CharSequence text, final M
349349
case Type.ID:
350350
case Type.IDREF:
351351
case Type.ENTITY:
352-
final StringValue stringValue = new StringValue(content, type);
352+
final StringValue stringValue = new StringValue(content, type, false);
353353
return new TextField(fieldName, stringValue.getStringValue(), store);
354354

355355
case Type.NOTATION:
@@ -496,7 +496,7 @@ protected void processText(final NodeId nodeId, final CharSequence text, final M
496496
case Type.ID:
497497
case Type.IDREF:
498498
case Type.ENTITY:
499-
final StringValue stringValue = new StringValue(content, type);
499+
final StringValue stringValue = new StringValue(content, type, false);
500500
bytesRef = new BytesRef(stringValue.toJavaObject(byte[].class));
501501
break;
502502

extensions/indexes/lucene/src/main/java/org/exist/xquery/modules/lucene/Field.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private AtomicValue stringToAtomic(final int type, final String value) throws XP
527527
case Type.ID:
528528
case Type.IDREF:
529529
case Type.ENTITY:
530-
return new StringValue(this, value, type);
530+
return new StringValue(this, value, type, false);
531531

532532
case Type.NOTATION:
533533
default:

0 commit comments

Comments
 (0)