[MarkLogic Dev General] Search - Additional Query

Vedavalli Radhika radhika.kv at gmail.com
Wed Mar 14 03:14:20 PDT 2012


I have fixed the options node as suggested. But my problem is still
not resolved.

I made one more level of progress. But still not able to fetch the
expected results.
With the below cts:search, I am able to retrieve the expected nodes.
for $x in cts:search(//sc:filter,cts:and-query
((cts:element-value-query(xs:QName("sc:filtertype"),"source"),
cts:directory-query("/my-directory/","infinity"))))
return $x

<v:results>
<ns2:filter>
  <ns2:filtertype name="Source">source</ns2:filtertype>
  <ns2:filtervalue name="ABCD">ABCDE</ns2:filtervalue>
  <ns2:filtervalue name="1234"> 12345</ns2:filtervalue>
</ns2:filter>
</v:results>

So, I tried to convert this cts:search into search:search. Made use of
the element value range constraint for filtertype, additional query
for the directory and searchable expression to request the specific
"filter" tag alone. But no facets are getting generated with the
searchable expression in place.
This issue is becoming a critical one to solve. Can someone help me in
attacking the problem.

let $options :=
<options xmlns="http://marklogic.com/appservices/search">
   <additional-query>{cts:directory-query("/my-directory/",
"infinity")}</additional-query>
    <constraint name="source">
        <range type="xs:string" facet="true"
collation="http://marklogic.com/collation/">
                          <element ns=" my-namespace " name="filtervalue" />
         <attribute name="name"/>
                             <facet-option>frequency-order</facet-option>
                             <facet-option>descending</facet-option>
        </range>
    </constraint>
   <mlsearch:operator name='searchable'>
   	<mlsearch:state name='filter'>
<searchable-expression
xmlns:sc="my-namespace">//sc:filter</searchable-expression>
</mlsearch:state>
 </mlsearch:operator>
</options>

let $result := search:search(“searchable:filter filtertype:source” ,$options)
return $result


> Date: Tue, 13 Mar 2012 14:41:52 -0700
> From: Danny Sokolsky <Danny.Sokolsky at marklogic.com>
> Subject: Re: [MarkLogic Dev General] Search - Additional Query
> To: MarkLogic Developer Discussion <general at developer.marklogic.com>
> Message-ID:
> 	<C9924D15B04672479B089F7D55FFC1322262136507 at EXCHG-BE.marklogic.com>
> Content-Type: text/plain; charset="us-ascii"
>
> That is not a valid options node you have.  I see several problems with it:
>
> 1) it is not in the http://marklogic.com/appservices/search namespace
> 2) there are 2 additional-query elements.  If you want to combine them, make
> an and-query of the 2 additional-query elements.
> 3) the second additional-query is not a query, it is a search.
>
> I recommend using search:check-options on your options node to make sure it
> is valid (or adding the <debug>true</debug> option to your options node.
>
> So maybe try fixing the options node and see if that gets you any farther.
>
> -Danny
>
>
> -----Original Message-----
> From: general-bounces at developer.marklogic.com
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Vedavalli
> Radhika
> Sent: Tuesday, March 13, 2012 6:15 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Search - Additional Query
>
> I wrongly typed the current query that I am using,
> It is the below:
> "let $options :=
> <options>
>
>     <additional-query>{cts:directory-query("/my-directory/",
> "infinity")}</additional-query>
>
> <additional-query>{cts:and-query(cts:element-value-query(xs:QName("sc:filtertype"),"source"))}</additional-query>
>
>     <constraint name="source">
>         <range type="xs:string" facet="true"
> collation="http://marklogic.com/collation/">
>                           <element ns="my-namespace" name="filtervalue" />
>  		   <attribute name="name" />
>                           <facet-option>frequency-order</facet-option>
>         </range>
>     </constraint>
> </options>
>
> let $result := mlsearch:search($queryString ,$options)
>
> return $result"
>
>
> On 3/13/12, Vedavalli Radhika <radhika.kv at gmail.com> wrote:
>> For the given format of xmls, I have to form facets of filtertype
>> elements which has filtertype value as "source" alone.
>>
>> <ns8:activityitem>
>> <ns5:filterlist>
>> <ns2:filterlist><ns2:filter>
>> <ns2:filtertype name="Source">source</ns2:filtertype>
>> <ns2:filtervalue name="ABCD">ABCDE</ns2:filtervalue>
>> <ns2:filtervalue name="1234">12345</ns2:filtervalue>
>> </ns2:filter>
>> </ns2:filterlist>
>> <ns2:filterlist>
>> <ns2:filter>
>> <ns2:filtertype name="Source">domain</ns2:filtertype>
>> <ns2:filtervalue name="FIVE">FIVES</ns2:filtervalue>
>> </ns2:filter>
>> </ns2:filterlist>
>> </ns5:filterlist>
>> </ns8:activityitem_marklogic>
>>
>> For the following code,
>>
>> let $options :=
>> <options>
>>
>>     <additional-query>{cts:directory-query("/my-directory/",
>> "infinity")}</additional-query>
>> <additional-query>{for $x in cts:search(//cdi:filterlist,
>> cts:directory-query("/my-directory/","infinity"))
>> return $x/sc:filterlist/sc:filter[sc:filtertype eq
>> "source"]/sc:filtervalue}</additional-query>
>>
>>     <constraint name="source">
>>         <range type="xs:string" facet="true"
>> collation="http://marklogic.com/collation/">
>>                           <element ns="my-namespace" name="filtervalue" />
>>  		   <attribute name="name" />
>>                           <facet-option>frequency-order</facet-option>
>>         </range>
>>     </constraint>
>> </options>
>>
>> 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>
>> </search:facet>
>>
>> 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,
>> cts:directory-query("/my-directory/","infinity"))
>> 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.
>>
>> Thanks,
>> Radhika.
>>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general


More information about the General mailing list