There is some explanation of a use case below; the actual question follows.
I am using ML search queries on some documents that contain elements of the form:
<resource>
<version>
<metadata label="author">Jim</metadata>
...
</version>
<version>
<metadata label="author">John</metadata>
...
</version>
</resource>
Note the versioning of metadata. Uppermost version element contains up-to-date info for the document.
The queries are based on user input; the user looks e. g. for documents, whose author is John.
I am not knowledgeable enough to combine attribute value and element/text value queries in a better way than this:
cts:near-query((cts:element-attribute-value-query(xs:QName("metadata"), xs:QName("label"), "author"), cts:element-value-query(xs:QName("metadata"), "John")), 0)
It does work though, so I am fine with it. What doesn't work is choosing only the last version in the resource (/resource/version[1]). If, at a certain point, the "author" was changed from "John" to "Jim", the document with the resource as shown above will always be found, because I don't know how to look only for values in the last (uppermost) version element. So I have to filter the results once more over XPath in a loop.
Is there a way to do this on an ML search query level?
You could create a field with a path that points to the
metadata
with the@label="author"
that is in the firstversion
element:/resource/version[1]/metadata[@label="author"]
and then you could use acts:field-value-query()
Then you could search that named field: