[MarkLogic Dev General] Search - Additional Query

Vedavalli Radhika radhika.kv at gmail.com
Tue Mar 13 03:36:28 PDT 2012

For the given format of xmls, I have to form facets of filtertype
elements which has filtertype value as "source" alone.

<ns2:filtertype name="Source">source</ns2:filtertype>
<ns2:filtervalue name="ABCD">ABCDE</ns2:filtervalue>
<ns2:filtervalue name="1234">12345</ns2:filtervalue>
<ns2:filtertype name="Source">domain</ns2:filtertype>
<ns2:filtervalue name="FIVE">FIVES</ns2:filtervalue>

For the following code,

let $options :=

<additional-query>{for $x in cts:search(//cdi:filterlist,
return $x/sc:filterlist/sc:filter[sc:filtertype eq

    <constraint name="source">
        <range type="xs:string" facet="true"
                          <element ns="my-namespace" name="filtervalue" />
 		   <attribute name="name" />

let $result := mlsearch:search($queryString ,$options)

return $result

The facet results are as follows:
<search:facet name="source">
<search:facet-value name="ABCD" count="1">ABCD</search:facet-value>
<search:facet-value name="1234" count="1">1234</search:facet-value>
<search:facet-value name="FIVE" count="1">FIVE</search:facet-value>

But whereas I expect only the first two entries.
The query is returning all filtervalues in the given xml whenever it
finds a filtertype element in it's xml with value as "source".
But I am expecting only the filtervalues for which the sibling node
filtertype has value as source.

I tried to build a xquery using xpath. This is giving me expected
results. But I am unable to fit this in the additional-query.

for $x in cts:search(//ns5:filterlist,
return $x/sc:filterlist/sc:filter[sc:filtertype eq "source"]/sc:filtervalue

When I include the above inside additional-query, I am getting the
following exception.
"XDMP-QUERYELEM: cts:query(<cts:and-query
xmlns:cts="http://marklogic.com/cts"><cts:and-query strength="20"
qtextjoin=""><cts:and-query qtextco...</cts:and-query>) -- Query
element contains unknown child: /cts:and-query"

1. Please help me resolve the issue.
2. I am also not sure if the above way is the best way to solve the
problem. Give me your suggestions on how can I best(in terms of
performance) solve the issue at hand.


More information about the General mailing list