I pursued this with MarkLogic Support and they supplied the answer<div><br></div><div><div><span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">We have checked your code and the problem seems to lie in the custom constraint code (b-custom-constraint.xqy):</span><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">
<span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">fn:string($right//cts:text/text())</span><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">
<span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">What&#39;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&#39;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.</span><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">
<br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">Looking at the custom term code, I think you could try doing this:</span><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">
<span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">fn:string(($right//cts:text)[1]/text())</span><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><br clear="none" style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">
<span style="font-family:Tahoma;text-align:-webkit-auto;font-size:medium">That will take the content of just the first cts:text node and use it for custom constraint parsing.</span></div></div><div><br>I tried it and it fixed it!</div>
<div><br>Regards,<br><br>Stuart</div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Thu, Jul 26, 2012 at 5:06 PM, Stuart Myles <span dir="ltr">&lt;<a href="mailto:stuart.myles@gmail.com" target="_blank">stuart.myles@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Any suggestions on why I get an XDMP-ARGTYPE error when I mix custom constraints with special handling of unconstrained terms in search:search?<div>
<br></div><div><div class="im"><div><div style="margin:0px 0px 20px;padding:0px;border:0px;outline:0px;font-size:16.363636016845703px;vertical-align:baseline;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial;line-height:14.545454025268555px">

<h3 style="margin:0px;padding:0px 0px 0px 45px;border:0px;outline:0px;font-size:14px;vertical-align:baseline;background-image:url(&#39;http://localhost:8000/qconsole/static/images/icons/icon-compile-error.png&#39;);color:rgb(34,34,34);background-repeat:no-repeat no-repeat">

[1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) fn:string((text{&quot;mitt&quot;}, text{&quot;mitt&quot;}, text{&quot;mitt&quot;}, ...)) -- arg1 is not of type item?</h3><p style="margin:0px;padding:0px 0px 0px 25px;border:0px;outline:0px;font-size:12px;vertical-align:baseline;color:rgb(76,76,76);text-align:left;font-weight:bold">

</p></div></div></div>As I describe below, either one on their own works fine.</div><div><br></div><div>Regards,<br><br>Stuart</div><div class="HOEnZb"><div class="h5"><div><br><br><div class="gmail_quote">On Mon, Jul 23, 2012 at 4:17 PM, Stuart Myles <span dir="ltr">&lt;<a href="mailto:stuart.myles@gmail.com" target="_blank">stuart.myles@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the search:search API, I can either have a custom constraint *or* special handling of unconstrained terms, but not both.<div>

<br></div><div>Here is a bit of code that illustrates what I&#39;m trying to do:</div><div><br>
</div><div><div><span style="border-collapse:separate;font-family:Tahoma;border-spacing:0px;font-size:medium"><a href="https://gist.github.com/3165844" target="_blank">https://gist.github.com/3165844</a></span></div></div>

<div><br></div>
<div><pre style="word-wrap:break-word;white-space:pre-wrap">xquery version &quot;1.0-ml&quot;;
import module namespace
  search = &quot;<a href="http://marklogic.com/appservices/search" target="_blank">http://marklogic.com/appservices/search</a>&quot;
  at &quot;/MarkLogic/appservices/search/search.xqy&quot;;

let $optionsconstraints :=
&lt;optionsconstraints xmlns=&quot;<a href="http://marklogic.com/appservices/search" target="_blank">http://marklogic.com/appservices/search</a>&quot;&gt;
&lt;constraint name=&quot;ovparty&quot;&gt;
    &lt;custom facet=&quot;false&quot;&gt;
        &lt;parse apply=&quot;ovparty&quot; ns=&quot;<a href="http://stuartmyles.com/ns/mysearch" target="_blank">http://stuartmyles.com/ns/mysearch</a>&quot; at=&quot;/b-custom-constraint.xqy&quot;/&gt;
    &lt;/custom&gt;
&lt;/constraint&gt;
&lt;/optionsconstraints&gt;

let $options :=
    &lt;options xmlns=&quot;<a href="http://marklogic.com/appservices/search" target="_blank">http://marklogic.com/appservices/search</a>&quot;&gt;
        {
          $optionsconstraints//search:constraint
        }
            &lt;term apply=&quot;myterm&quot; ns=&quot;<a href="http://try.marklogic.com/search-options" target="_blank">http://try.marklogic.com/search-options</a>&quot;
                         at=&quot;/search-options.xqy&quot;&gt;
              &lt;empty apply=&quot;all-results&quot;/&gt;
            &lt;/term&gt;
            &lt;/options&gt;

let $optionsgood :=
    &lt;options xmlns=&quot;<a href="http://marklogic.com/appservices/search" target="_blank">http://marklogic.com/appservices/search</a>&quot;&gt;
        {   $optionsconstraints//search:constraint}
            &lt;/options&gt;

return search:search(&quot;ovparty:mitt&quot;, $options)</pre><pre style="word-wrap:break-word;white-space:pre-wrap"><div style="font-family:arial;white-space:normal">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:</div>


<div style="font-family:arial;white-space:normal"><br></div><div style="font-family:arial;white-space:normal"><div><span style="border-collapse:separate;font-family:Tahoma;border-spacing:0px;font-size:medium"><a href="https://gist.github.com/3165861" target="_blank">https://gist.github.com/3165861</a></span></div>


<div><br></div><div>However, when I use $options instead, I get an error:</div><div><br></div><div><div style="margin:0px 0px 20px;padding:0px;border:0px;outline:0px;font-size:16.363636016845703px;vertical-align:baseline;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial;line-height:14.545454025268555px">


<h3 style="margin:0px;padding:0px 0px 0px 45px;border:0px;outline:0px;font-size:14px;vertical-align:baseline;background-image:url(&#39;http://localhost:8000/qconsole/static/images/icons/icon-compile-error.png&#39;);color:rgb(34,34,34);background-repeat:no-repeat no-repeat">


[1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) fn:string((text{&quot;mitt&quot;}, text{&quot;mitt&quot;}, text{&quot;mitt&quot;}, ...)) -- arg1 is not of type item?</h3><p style="margin:0px;padding:0px 0px 0px 25px;border:0px;outline:0px;font-size:12px;vertical-align:baseline;color:rgb(76,76,76);text-align:left;font-weight:bold">


</p></div></div><div>That&#39;s because I apply the function &quot;myterm&quot; to unconstrained terms. The function myterm is defined in search-constraints.xqy:</div><div><br></div><div><div><span style="border-collapse:separate;font-family:Tahoma;border-spacing:0px;font-size:medium"><a href="https://gist.github.com/3165889" target="_blank">https://gist.github.com/3165889</a></span></div>


</div><div><br></div><div>The &quot;myterm&quot; function is based very heavily on the one provided in the &quot;Ninja&quot; tutorial:</div><div><br></div><div><a href="http://developer.marklogic.com/try/ninja/page13" target="_blank">http://developer.marklogic.com/try/ninja/page13</a>
</div><div><br></div><div>So, how do I get these two functions to co-exist?</div><div><br></div><div>I&#39;m running MarkLogic 5.0 under Windows XP.</div><div><br></div><div><table cellspacing="0" cellpadding="0" border="0" width="100%">


<tbody><tr><td align="left" width="32%" style="font-size:8pt;font-family:Arial,Helvetica"><br><table cellspacing="0" cellpadding="0" border="0" style="background-color:rgb(205,158,85)">
<tbody><tr valign="top"><td align="left" width="8" style="font-size:8pt;font-family:Arial,Helvetica"><img src="http://localhost:8001/images/left-edge.gif" alt="" width="8" height="90" style="vertical-align:top"></td><td align="left" width="100%" valign="top" style="font-size:8pt;font-family:Arial,Helvetica;background-image:url(&#39;http://localhost:8001/images/top-left-background.gif&#39;);background-repeat:repeat no-repeat">


<div><img src="http://localhost:8001/images/varspace.gif" alt="" height="5" width="244"></div><div style="padding-top:8px"><a href="http://localhost:8001/" style="color:white;font-weight:bold;font-family:Arial,Helvetica,sans-serif;font-size:8pt;text-decoration:none" target="_blank"><img src="http://localhost:8001/images/marklogic-server.gif" alt="MarkLogic Server" width="242" height="26" border="0"></a></div>


<div><a href="http://localhost:8001/" target="_blank"><img src="http://localhost:8001/images/edition-standard.gif" alt="Standard Edition" width="160" height="10" border="0"></a></div><div style="padding-top:16px;font-family:Verdana;font-weight:bold">


5.0-1.2</div></td></tr></tbody></table></td></tr></tbody></table></div></div><br>
<span style="font-family:arial;white-space:normal">Thanks in advance for any help!</span>
</pre><pre style="word-wrap:break-word;white-space:pre-wrap"><span style="font-family:arial;white-space:normal"><br></span></pre><pre style="word-wrap:break-word;white-space:pre-wrap"><span style="font-family:arial;white-space:normal">Regards,</span></pre>


<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="font-family:arial;white-space:normal"><br></span></pre><pre style="word-wrap:break-word;white-space:pre-wrap"><span style="font-family:arial;white-space:normal">Stuart</span></pre>


<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="font-family:arial;white-space:normal"><br></span></pre></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>