marklogic / java-client-api

Java client for the MarkLogic enterprise NoSQL database
https://docs.marklogic.com/guide/java
Apache License 2.0
58 stars 72 forks source link

Support for cts:annotation in cts:query? #1648

Open ralfhergert opened 6 months ago

ralfhergert commented 6 months ago

CtsQueries allow to be enriched with cts:annotation-elements: https://docs.marklogic.com/guide/search-dev/cts_query#id_28038 Those elements are ignored by MarkLogic when the query is executed. cts:annotations can be used for various purposes (like documentation) and in our case we use it as a marker-element to identify certain parts of the query to be able to modify and manipulate them later after the creation.

Do the QueryBuilders support to add annotation-elements? (I searched, but didn't find it yet.)

rjrudin commented 6 months ago

Correct, there's not support for adding annotation elements. What's your use case for them? Like would you eventually serialize the query to a place where a developer / user would see it?

ralfhergert commented 6 months ago

Hi @rjrudin, we are starting to use alerts in MarkLogic server. The queries used in the alert-rules are composed of two parts: one is given by our customers and the other is given by our rights and roles model. From time to time the rights and roles part is updated and thus we need to update the queries in all alert-rules. Here we only want to modify the half of the query that corresponds to the rights and roles, we absolutely do not want to touch the part of the query given by our customers. - Annotations help us to identify the parts correctly.

rjrudin commented 6 months ago

Hi @ralfhergert - thanks for the feedback. It's not directly supported today via the Java Client, though you would at least have a workaround of:

  1. Serialize your query to XML.
  2. Manually add the annotation elements (annoying, yes, but I don't know of a better way; I would use JDOM2 for this).
  3. Submit your serialized query.