Nikunj Vekariya
Nikunj Vekariya

Reputation: 833

Unexpected behavior shown by search:search in marklogic

I am using search:search for searching the below kind of structure:

search:search(
  "",
  <options>
    <additional-query>
      {
        cts:and-query((
            cts:collection-query("A"),
            cts:not-query(cts:collection-query("B")),
            cts:not-query(cts:collection-query("C")),
            cts:and-query((
                cts:element-value-query(
                  xs:QName("uri"),
                  cts:search(collection("A"),
                    cts:element-value-query(xs:QName("uri"),
                      cts:search(collection("B"),
                        cts:element-value-query(xs:QName("uri"),
                          cts:search(collection("C"),cts:word-query("Hello"))/fn:base-uri()
                        )
                      )/fn:base-uri()
                    )
                  )/fn:base-uri()
                ),
                dls:documents-query()
            ))
        ))
      }
    </additional-query>
  </options>,1,10)

It gives 0 result.

However if I try this it gives required result

let $a :=
  cts:search(collection("A"),
    cts:element-value-query(xs:QName("uri"),
      cts:search(collection("B"),
        cts:element-value-query(xs:QName("uri"),
          cts:search(collection("C"),cts:word-query("Hello"))/fn:base-uri()
        )
      )/fn:base-uri()
    )
  )/fn:base-uri()
return
  search:search(
    "",
    <options>
      <additional-query>
        {
          cts:and-query((
              cts:collection-query("A"),
              cts:not-query(cts:collection-query("B")),
              cts:not-query(cts:collection-query("C")),
              cts:and-query((
                  cts:element-value-query(
                    xs:QName("uri"),
                    $a
                  ),
                  dls:documents-query()
              ))
          ))
        }
      </additional-query>
    </options>, 1, 10)

It solves the problem where some section is taken out and then passed in search:search options. Please look into it and help

Upvotes: 0

Views: 103

Answers (1)

ehennum
ehennum

Reputation: 7335

You can't embed a cts:query directly in search:options.

Instead, try:

<search:options>
<search:additional-query>{...your cts:query here ...}</search:additional-query>
</search:options>

For more information, see:

http://docs.marklogic.com/guide/rest-dev/appendixb#id_98507

Also, if you want to use a subquery to retrieve values for use as criteria, you should create range indexes on the elements that are the source of the values and the target of the query and use a cts:values() lexicon lookup. For more information, see:

http://docs.marklogic.com/cts:values

Hoping that helps,

Upvotes: 2

Related Questions