I have a problem with incorrect results during sending wildcarded query in my Java project. On my Marklogic database I do have saved multiple json files with same structure. I want to receive those jsons which in field named "icsList" (It is List of Strings) starts with given String.
Example icsList in json looks like:
- "icsList": ["11.040.40", "12.50.80"]
- "icsList": ["12.50.60"]
- "icsList": ["50.010.10"]
My example results:
Request - String "50" Result - All jsons (even those which do not have "50" in their icsList)
Request - String "50." Result - Jsons that have "50." inside icsList (for example: "50.010.10", "50.010.20" but also "12.50.60")
As I mantioned earlier my primary goal is to get all jsons which in field named "icsList" STARTS with given String. My secound goal is to get rid of necessary dot at the end of request String.
My code is:
StructuredQueryBuilder sqb = new StructuredQueryBuilder();
String[] wordOptions = {"wildcarded"};
StructuredQueryDefinition queryDefinitionIcs = sqb.word(sqb.jsonProperty("icsList"),
null, wordOptions, 1, searchText + "*");
StructuredQueryDefinition query = sqb.and(queryDefinitionIcs);
query.setCollections(DocumentCollection.ATTRIBUTES.getName());
try (DocumentPage search = jsonDocumentManager.search(query, 1L)) {
JacksonHandle handle = new JacksonHandle();
List<DocumentAttributes> documentAttributes = StreamSupport.stream(search.spliterator(), false)
.map(v -> mapToDocumentAttributes(handle, v))
.toList();
}
private DocumentAttributes mapToDocumentAttributes(JacksonHandle handle, DocumentRecord v) {
try {
var doc = objectMapper.treeToValue(v.getContent(handle).get(), DocumentAttributes.class);
return doc;
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
In pom.xml I do have:
<dependency>
<groupId>com.marklogic</groupId>
<artifactId>marklogic-client-api</artifactId>
<version>5.5.3</version>
</dependency>