Search code examples
marklogicmarklogic-8

cts:value-co-occurrences returning empty sequence


I am trying to find co-occurrences of all documents which have a property <id> in the document-properties.. Following is the code I am doing to list the co-occurrences and is not working.. can someone suggest what I am doing wrong.

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace prop = "http://marklogic.com/xdmp/property";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";


 cts:value-co-occurrences(
              cts:element-reference(xs:QName('prop:id')),
              cts:uri-reference())

I did create the element range index on this property enter image description here


Solution

  • Note: I have edited this answer after acceptance because I gave three items to look at. The edit is to highlight the part of the answer that gave the solution


    Solution: - Namespace in properties fragment was different

    • This is sometimes confusing for people.
    • There is an XML document in the property fragment - always.
    • The node itself declares a namespace, but it is prefixed as 'prop'.
    • However, the properties you add (XML elements) are not under the above namespace - unless of course you actually use the prop prefix yourself.
    • End result for this challenge was that the user created an index on an element in the properties fragment and scoped the index to the properties namespace. This created a totally valid index - just empty because no elements matched.

    Original wording of response:

    Are you sure the element in question is actually in the properties namespace as your index shows? A quick dump of cts:element-values may show this. I mention this because adding properties to the properties fragment does not infer that they are in the properties namespace.

    --


    Other ideas - not the answer, but path of investigation

    I think you are looking for cts:value-tuples and not co-occurance based on your example.


    However: from your problem statement, why do you not just use cts:uris() constrained by an cts:element-query() on the property fragment (and all without a range index)

    This can tell you all URIs where element my-element exists in the properties fragment:

    cts:uris("", (),
      cts:properties-fragment-query(
        cts:element-query(xs:QName("my-element"),
          cts:and-query( () )) 
        )
    )