Let's assume I have two documents:
<doc>
   <values>
      <a datetime="2010-09-26T05:00:00-05:00">
         <occurence>the dog barked</occurence>
      </a>
      <a datetime="2010-09-27T05:00:00-05:00">
         <occurence>the dog barked</occurence>
      </a>
      <a datetime="2010-09-28T05:00:00-05:00">
         <occurence>the dog barked</occurence>
      </a>
  </values>
</doc>

<doc>
   <values>
      <a datetime="2010-09-26T05:00:00-05:00">
         <occurence>the dog barked</occurence>
      </a>
      <a datetime="2010-09-27T05:00:00-05:00">
         <occurence>the dog barked</occurence>
      </a>
      <a datetime="2010-09-28T05:00:00-05:00">
         <occurence>a cat meowed</occurence>
      </a>
  </values>
</doc>


Let's say i want to search on that in these human terms:
  "Get me all the documents where "the dog" barked after 9/26 at least
twice"
To put together the date time and the occurrence I can use an element-query.

  cts:search(
    fn:collection(),
    cts:element-query(
      fn:QName("a"),
      cts:and-query(
        (
          cts:element-attribute-range-query(
            fn:QName("a"),
            fn:QName("","datetime"),
            ">",
            xs:dateTime('2010-09-26T05:00:00-05:00')
          ),
          cts:element-word-query(fn:QName("occurence"),"the dog barked")
        )
      )
    )
  )

To find multiple occurrences I can use 'min-occurs=x' given:
  cts:element-word-query(fn:QName("occurence"),"the dog
barked","min-occurs=2")

Where I have a problem is tying them both together.
  cts:search(
    fn:collection(),
    cts:element-query(
      fn:QName("a"),
      cts:and-query(
        (
          cts:element-attribute-range-query(
            fn:QName("a"),
            fn:QName("","datetime"),
            ">",
            xs:dateTime('2010-09-26T05:00:00-05:00')
          ),
          cts:element-word-query(fn:QName("occurence"),"the dog barked",
"min-occurs=2")
        )
      )
    )
  )
This did not work, because there is only 1 occurrence node within in <a>
node, thereby returning nothing.

So this was tried:
  cts:search(
    fn:collection(),
    cts:and-query(
      (
        cts:element-query(
          fn:QName("a"),
          cts:and-query(
            (
              cts:element-attribute-range-query(
                fn:QName("a"),
                fn:QName("","datetime"),
                ">",
                xs:dateTime('2010-09-26T05:00:00-05:00')
              ),
              cts:element-word-query(fn:QName("occurence"),"the dog barked")
            )
          ),
          cts:element-word-query(fn:QName("occurence"),"the dog
barked","min-occurs=2")
        )
    )
  )
This did not work, because it matched the original and-query, but it also
separately matched the occurrence query, so it returned both documents.

Could anyone shed some light on how to tie these relationships together to
search based on the human readable requirements?
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to