[MarkLogic Dev General] Re: General Digest, Vol 54, Issue 15

Michael Blakeley michael.blakeley at marklogic.com
Thu Dec 11 12:18:39 PST 2008


Dave,

One problem is that your expected output isn't a valid cts:query.

cts:element-word-query(QName("AUTHOR"),
    cts:and-query(cts:word-query("john"), cts:word-query("smith")))
=>
[1.0-ml] XDMP-TOOFEWARGS: (err:XPST0017) QName("AUTHOR") -- Too few 
args, expected 2 but got 1

It's relatively easy to fix two typos in the above, but this still 
throws XDMP-ARGTYPE, because cts:element-word-query() does not support 
what you're trying to do:

cts:element-word-query(xs:QName("AUTHOR"),
   cts:and-query((cts:word-query("john"), cts:word-query("smith"))))

Take a look at the function signature at 
http://developer.marklogic.com/pubs/4.0/apidocs/cts-query.html#cts:element-word-query

> cts:element-word-query(
> 	$element-name as xs:QName*,
> 	$text as xs:string*,
> 	[$options as xs:string*],
> 	[$weight as xs:double]
> )  as  cts:element-word-query
[ snip ]
> $text : Some words or phrases to match. When multiple strings are
> specified, the query matches if any string matches.

Since you want AND, rather than OR, cts:element-query() is necessary 
after all.

cts:element-query(xs:QName("AUTHOR"),
   cts:and-query((cts:word-query("john"), cts:word-query("smith"))))

That query would match your use-case, but lib-parser doesn't implement a 
syntax that would generate it query for you. You could extend lib-parser 
to support the syntax you have in mind. If you do, please share your patch.

-- Mike

On 2008-12-11 09:47, Dave Feldmeier wrote:

> "(AUTHOR:john AUTHOR:smith)" is doing what I expect, but I need a different
> query in addition to this one. Let me give you some context. Suppose that we
> have two documents:
>
>      <DOCUMENT>
>      <AUTHOR>smith, john</AUTHOR>
>      </DOCUMENT
>
>      <DOCUMENT>
>      <AUTHOR>jones, john</AUTHOR>
>      <AUTHOR>smith, steve</AUTHOR>
>      </DOCUMENT
>
> The problem with the query above is that it will match both documents, but I
> want a query that matches only the first document. In other words, I want the
> AND to be performed within any single AUTHOR field.
>
> The obvious syntax for this is: "AUTHOR:(john smith)". However, lib-parse
> appears to parse this as if the query were as follows: 'AUTHOR:"" (john smith)'
> - in other words, it's looking for an AUTHOR field with "" (and there is none),
> so the entire query returns zero results.
>
> What I expected it to do is something like:
>
>      (cts:element-word-query(QName("AUTHOR"),
>      cts:and-query(cts:word-query("john"), cts:word-query("smith"))))


More information about the General mailing list