1

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

3
  • Was there an error message? Mar 15, 2016 at 17:31
  • Please post a sample properties fragment so that we can verify that the element in question is actually in the properties namespace. Mar 15, 2016 at 18:23
  • Just tried this with some data I had handy -- I got no results until I fixed a namespace problem, then I got results. Mar 15, 2016 at 18:53

2 Answers 2

5

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( () )) 
    )
)
5
  • I tried this cts:value-tuples( (cts:element-reference(xs:QName('prop:id')), cts:uri-reference()),('properties')) .. I still get your query returned an empty sequence
    – Ravi
    Mar 15, 2016 at 18:15
  • The reason I want co-occurrences is that there might be documents with the same id, so I only want one document-uri for a given search criteria.. I have documents and each document have artifact documents that have same <id> property and I want to get only one document for a given <id> for a given search criteria
    – Ravi
    Mar 15, 2016 at 18:18
  • I think the only real difference between cts:value-co-occurrences() and cts:value-tuples is that the latter allows you to specify more than two index references. Mar 15, 2016 at 18:55
  • Yup My bad it was a namespace issue, when setting the properties I did not set the namespace for my properties..
    – Ravi
    Mar 15, 2016 at 19:50
  • Nice! glad it worked. I'll adjust the answer so it is clear which item was the culprit - but Ill leave the others as reference. Mar 15, 2016 at 20:14
1

No error message provided, so this is a guess. Make sure you have the URI lexicon turned on -- cts:uri-reference will throw an error otherwise.

1
  • Hmm.. I do not get any error.. just says your query returned an empty sequence ..But when I do the same, but instead of document-properties I do an xml tag inside the documents which have element-range index it works..
    – Ravi
    Mar 15, 2016 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.