I pursued this with MarkLogic Support and they supplied the answer We have checked your code and the problem seems to lie in the custom constraint code (b-custom-constraint.xqy): fn:string($right//cts:text/text())
What's happening is that the custom constraint code assumes that there will be one cts:text element; when the default term parser is used that's true, but the custom term code is parsing terms to an or-query, which means that there is now a sequence of cts:text nodes under $right. Looking at the custom term code, I think you could try doing this: fn:string(($right//cts:text)[1]/text()) That will take the content of just the first cts:text node and use it for custom constraint parsing. I tried it and it fixed it! Regards, Stuart On Thu, Jul 26, 2012 at 5:06 PM, Stuart Myles <stuart.my...@gmail.com>wrote: > Any suggestions on why I get an XDMP-ARGTYPE error when I mix custom > constraints with special handling of unconstrained terms in search:search? > > [1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) fn:string((text{"mitt"}, > text{"mitt"}, text{"mitt"}, ...)) -- arg1 is not of type item? > > As I describe below, either one on their own works fine. > > Regards, > > Stuart > > > On Mon, Jul 23, 2012 at 4:17 PM, Stuart Myles <stuart.my...@gmail.com>wrote: > >> In the search:search API, I can either have a custom constraint *or* >> special handling of unconstrained terms, but not both. >> >> Here is a bit of code that illustrates what I'm trying to do: >> >> https://gist.github.com/3165844 >> >> xquery version "1.0-ml"; >> import module namespace >> search = "http://marklogic.com/appservices/search" >> at "/MarkLogic/appservices/search/search.xqy"; >> >> let $optionsconstraints := >> <optionsconstraints xmlns="http://marklogic.com/appservices/search"> >> <constraint name="ovparty"> >> <custom facet="false"> >> <parse apply="ovparty" ns="http://stuartmyles.com/ns/mysearch" >> at="/b-custom-constraint.xqy"/> >> </custom> >> </constraint> >> </optionsconstraints> >> >> let $options := >> <options xmlns="http://marklogic.com/appservices/search"> >> { >> $optionsconstraints//search:constraint >> } >> <term apply="myterm" ns="http://try.marklogic.com/search-options" >> at="/search-options.xqy"> >> <empty apply="all-results"/> >> </term> >> </options> >> >> let $optionsgood := >> <options xmlns="http://marklogic.com/appservices/search"> >> { $optionsconstraints//search:constraint} >> </options> >> >> return search:search("ovparty:mitt", $options) >> >> When I pass $optionsgood to search:search, I can successfully search against >> my ovparty constraint, which is defined in the file b-custom-constrain.xqy: >> >> >> https://gist.github.com/3165861 >> >> >> However, when I use $options instead, I get an error: >> >> >> >> >> [1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) fn:string((text{"mitt"}, text{"mitt"}, >> text{"mitt"}, ...)) -- arg1 is not of type item? >> >> >> That's because I apply the function "myterm" to unconstrained terms. The >> function myterm is defined in search-constraints.xqy: >> >> https://gist.github.com/3165889 >> >> >> The "myterm" function is based very heavily on the one provided in the >> "Ninja" tutorial: >> >> http://developer.marklogic.com/try/ninja/page13 >> >> So, how do I get these two functions to co-exist? >> >> I'm running MarkLogic 5.0 under Windows XP. >> >> >> >> >> [image: MarkLogic Server] <http://localhost:8001/> >> >> [image: Standard Edition] <http://localhost:8001/> >> >> >> 5.0-1.2 >> >> Thanks in advance for any help! >> >> >> Regards, >> >> >> Stuart >> >> >> >
_______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general