Will, As suggested, I included the term in option and rectified the error with element-attribute constraint. The error is gone. But I could make no progress on the facets.
To reiterate my problem - The facets are not getting generated as expected. For the filtertype as source, I want to get the immediate filtervalue siblings. But it picks up all the filtervalue elements in the whole xml in which there is indeed a filtertype element with value as source. Here are the results import module namespace mlsearch="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; declare namespace ml="http://services.mycompany.com/shared/xmlschema/activityitem_marklogic/2"; declare namespace sc="http://services.mycompany.com/shared/xmlschema/servicescommon/2"; declare namespace cdi="http://services.mycompany.com/shared/xmlschema/coredataitem/2"; let $options2 := <options xmlns="http://marklogic.com/appservices/search"> <additional-query>{cts:and-query(cts:element-query(xs:QName("sc:filter"),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="http://services.mycompany.com/shared/xmlschema/servicescommon/2" name="filtervalue" /> <attribute ns="" name="name" /> <facet-option>frequency-order</facet-option> <facet-option>ascending</facet-option> </range> </constraint> <searchable-expression xmlns:sc="http://services.mycompany.com/shared/xmlschema/servicescommon/2">//sc:filter</searchable-expression> <debug>true</debug> <term><empty apply="all-results" /></term> </options> let $result2 := mlsearch:search(" " ,$options2) return $result2 <search:response total="1" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search"> <search:result index="1" uri="/abc.xml" path="fn:doc("/abc.xml")/*:activityitem_marklogic/*:filterlist[2]/*:filterlist/*:filter" score="18432" confidence="0.674626" fitness="0.674626"> <search:snippet> <search:match path="fn:doc("/abc.xml")/*:activityitem_marklogic/*:filterlist[2]/*:filterlist/*:filter">source NjQxOQ</search:match> </search:snippet> </search:result> <search:facet name="source"> <search:facet-value name="SOURCE" count="1">SOURCE</search:facet-value> <search:facet-value name="DOMAIN" count="1">DOMAIN</search:facet-value> </search:facet> <search:qtext> </search:qtext> <search:report id="SEARCH-FLWOR">(cts:search(//sc:filter, cts:and-query(cts:element-query(fn:QName("http://services.mycompany.com/shared/xmlschema/servicescommon/2", "filter"), cts:element-value-query(fn:QName("http://services.mycompany.com/shared/xmlschema/servicescommon/2", "filtertype"), "source", ("lang=en"), 1), ()), ()), ("score-logtfidf"), 1))[1 to 10]</search:report> <search:metrics> <search:query-resolution-time>PT0.078S</search:query-resolution-time> <search:facet-resolution-time>PT0S</search:facet-resolution-time> <search:snippet-resolution-time>PT0S</search:snippet-resolution-time> <search:total-time>PT0.094S</search:total-time> </search:metrics> </search:response> > Date: Wed, 14 Mar 2012 18:04:11 +0000 > From: Will Thompson <[email protected]> > Subject: Re: [MarkLogic Dev General] Search - Additional Query > To: MarkLogic Developer Discussion <[email protected]> > Message-ID: > <[email protected]> > Content-Type: text/plain; charset="us-ascii" > > By default an empty query returns no results. To change the behavior you > need to add to options: > > <term><empty apply="all-results" /></term> > > Also note the options validation error you are getting in your results: > > XDMP-VALIDATEMISSINGATTR: > (err:XQDY0027) validate strict { $opt } -- Missing required attribute: > Found (@name) but required (@ns & @name) at > /search:options/search:constraint/search:range/search:attribute using schema > "search.xsd" > > This is because one of your constraints is invalid. > > I would recommend reading the Search API output more carefully. The > information it provides can help you through debugging most of the time. > > -W > > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Vedavalli > Radhika > Sent: Wednesday, March 14, 2012 10:37 AM > To: [email protected] > Subject: Re: [MarkLogic Dev General] Search - Additional Query > > This is the query that I had tried and results with debug = true. > import module namespace > mlsearch="http://marklogic.com/appservices/search" at > "/MarkLogic/appservices/search/search.xqy"; > declare namespace > ml="http://services.mycompany.com/shared/xmlschema/activityitem_marklogic/2"; > declare namespace > sc="http://services.mycompany.com/shared/xmlschema/servicescommon/2"; > declare namespace > cdi="http://services.mycompany.com/shared/xmlschema/coredataitem/2"; > > let $options2 := > <options xmlns="http://marklogic.com/appservices/search"> > > <additional-query>{cts:and-query(cts:element-query(xs:QName("sc:filter"),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="http://services.mycompany.com/shared/xmlschema/servicescommon/2" > name="filtervalue" /> > <attribute name="name" /> > <facet-option>frequency-order</facet-option> > <facet-option>ascending</facet-option> > </range> > </constraint> > <searchable-expression > xmlns:sc="http://services.mycompany.com/shared/xmlschema/servicescommon/2">//sc:filter</searchable-expression> > <debug>true</debug> > </options> > > let $result2 := mlsearch:search(" " ,$options2) > > return $result2 > > <search:response total="1" start="1" page-length="10" xmlns="" > xmlns:search="http://marklogic.com/appservices/search"> > <search:result index="1" uri="/abc.xml" > path="fn:doc("/abc.xml")/*:activityitem_marklogic/*:filterlist[2]/*:filterlist/*:filter" > score="18432" confidence="0.674626" fitness="0.674626"> > <search:snippet> > <search:match > path="fn:doc("/abc.xml")/*:activityitem_marklogic/*:filterlist[2]/*:filterlist/*:filter">source > NjQxOQ</search:match> > </search:snippet> > </search:result> > <search:facet name="source"> > <search:facet-value name="SOURCE" count="1">SOURCE</search:facet-value> > <search:facet-value name="DOMAIN" count="1">DOMAIN</search:facet-value> > </search:facet> > <search:qtext> </search:qtext> > <search:report id="SEARCH-SCHEMAINVALID"><error:format-string > xmlns:error="http://marklogic.com/xdmp/error">XDMP-VALIDATEMISSINGATTR: > (err:XQDY0027) validate strict { $opt } -- Missing required attribute: > Found (@name) but required (@ns & @name) at > /search:options/search:constraint/search:range/search:attribute using > schema "search.xsd"</error:format-string><error:data > xmlns:error="http://marklogic.com/xdmp/error"> > <error:datum>(@name)</error:datum> > <error:datum>(@ns & @name)</error:datum> > > <error:datum>/search:options/search:constraint/search:range/search:attribute</error:datum> > <error:datum>"search.xsd"</error:datum> > </error:data></search:report> > <search:report id="SEARCH-FLWOR">(cts:search(//sc:filter, > cts:and-query(cts:element-query(fn:QName("http://services.mycompany.com/shared/xmlschema/servicescommon/2", > "filter"), > cts:element-value-query(fn:QName("http://services.mycompany.com/shared/xmlschema/servicescommon/2", > "filtertype"), "source", ("lang=en"), 1), ()), ()), > ("score-logtfidf"), 1))[1 to 10]</search:report> > <search:metrics> > <search:query-resolution-time>PT0.172S</search:query-resolution-time> > <search:facet-resolution-time>PT0S</search:facet-resolution-time> > > <search:snippet-resolution-time>PT0.016S</search:snippet-resolution-time> > <search:total-time>PT0.188S</search:total-time> > </search:metrics> > </search:response> > > And there is only one document in the database - /abc.xml > > <ns8:activityitem_marklogic xml:lang="en" > xmlns:ns2="http://services.mycompany.com/shared/xmlschema/servicescommon/2" > xmlns:ns5="http://services.mycompany.com/shared/xmlschema/coredataitem/2" > xmlns:ns8="http://services.mycompany.com/shared/xmlschema/activityitem_marklogic/2"> > <ns5:filterlist connector="and"> > <ns2:filterlist connector="or"> > <ns2:filter> > <ns2:filtertype name="Source">domain</ns2:filtertype> > <ns2:filtervalue name="DOMAIN">NjQxOQ</ns2:filtervalue> > </ns2:filter> > </ns2:filterlist> > </ns5:filterlist> > <ns5:filterlist connector="and"> > <ns2:filterlist connector="or"> > <ns2:filter> > <ns2:filtertype name="Source">source</ns2:filtertype> > <ns2:filtervalue name="SOURCE">NjQxOQ</ns2:filtervalue> > </ns2:filter> > </ns2:filterlist> > </ns5:filterlist> > </ns8:activityitem_marklogic> > >> Date: Wed, 14 Mar 2012 16:53:52 +0000 >> From: Will Thompson <[email protected]> >> Subject: Re: [MarkLogic Dev General] Search - Additional Query >> To: MarkLogic Developer Discussion <[email protected]>, >> "[email protected]" <[email protected]> >> Message-ID: >> <[email protected]> >> Content-Type: text/plain; charset="us-ascii" >> >> It may just be a typo, but this options node is missing some closing tags. >> Try search:check-options($OPTIONS) before executing your search:search >> call. >> >> -Will >> >> -----Original Message----- >> From: [email protected] >> [mailto:[email protected]] On Behalf Of Vedavalli >> Radhika >> Sent: Wednesday, March 14, 2012 4:38 AM >> To: [email protected]; [email protected] >> Subject: Re: [MarkLogic Dev General] Search - Additional Query >> >> I even tried to remove the filtertype constraint and searchable >> expressions and use element query in additional query as mentioned in >> the post - "Using additional-query with cts:search" by Geert Josten. >> This too did not help. No results or facets are returned if I use the >> below additional query. >> >> <additional-query>{cts:element-query(xs:QName("sc:filter"),cts:element-value-query(xs:QName("sc:filtertype"),"source"))}</additional-query> >> >> Previous query: >> let $options := >> <options xmlns="http://marklogic.com/appservices/search"> >> <additional-query>{cts:directory-query("/my-directory/", >> "infinity")}</additional-query> >> <constraint name="filtertype"> >> <value type="xs:string" facet="false" >> collation="http://marklogic.com/collation/"> >> <element ns="my-namespace" name="filtertype" /> >> <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> >> </options> >> >> let $result := search:search("searchable:filter filtertype:source" >> ,$options) >> return $result >> >> >> On 3/14/12, Vedavalli Radhika <[email protected]> wrote: >>> 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 <[email protected]> >>>> Subject: Re: [MarkLogic Dev General] Search - Additional Query >>>> To: MarkLogic Developer Discussion <[email protected]> >>>> Message-ID: >>>> <c9924d15b04672479b089f7d55ffc1322262136...@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: [email protected] >>>> [mailto:[email protected]] 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 <[email protected]> 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 >>>> [email protected] >>>> http://developer.marklogic.com/mailman/listinfo/general >>> >> > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > > > ------------------------------ > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > > > End of General Digest, Vol 93, Issue 28 > *************************************** > _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
