You should be able to pass in the not-query using search:search's <additional-query> option, if that's what you want.
But if you want to translate "title:null" to a not query, I think you'd need to create a custom constraint. Here's a blog article by Dave Cassel about those: http://blog.davidcassel.net/2011/07/a-custom-facet-for-the-search-api/ If you only need it to be a constraint (and not a facet), all you need to implement is the search:parse() function, so it would look something like this (untested): declare function facet:parse( $constraint-qtext as xs:string, $right as schema-element(cts:query)) as schema-element(cts:query) { let $text := string($right//cts:text), $query := if ($text eq 'null') then cts:not-query(cts:element-query(xs:QName("TITLE"), cts:and-query(()))) else cts:element-query(xs:QName("TITLE"), $text) return <temp>{$query}</temp>/* }; The <temp> element is just used as a temporary parent element for converting the cts:query value to a <cts:query> element. If you're getting unexpected results from negated queries, you need to make sure that the original query does not include any false positives. False positives are normally fine (because they can get filtered out later). But if you negate the query using cts:not-query (which means get all documents except those matching this query), then false positives turn into false negatives and hence missing results (and filtering can't help you there as it only removes candidate results). Moral of the story with cts:not-query() is to use it very cautiously—only in places where you know the negated query won't return false positives. A query for the presence of <TITLE> should fall into that category (fully resolvable from the Universal Index). Evan Lenz Software Developer, Community MarkLogic Corporation http://developer.marklogic.com From: Michael Sokolov <[email protected]<mailto:[email protected]>> Reply-To: General MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Date: Tue, 3 Jan 2012 06:41:00 -0800 To: General MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Subject: Re: [MarkLogic Dev General] Search documents without a node tag You can do cts:not-query(cts:element-query(xs:QName("TITLE"), cts:and-query(()))) to find documents that don't have any TITLE elements. I don't know how to do that in the search api, though. -Mike On 1/3/2012 8:48 AM, Mariano Grau Calín wrote: Hi all, We want to find documents where a node tag not exist. By example, this query return documents where TITLE has a value. The opposite we want. doc()/DOC[AGENCY='EFE' and TITLE] If we try to negate query, result is not like expected. doc()/DOC[AGENCY='Grupo Joly' and TITLE[text() is null]] (: same result :) doc()/DOC[AGENCY='EFE' and not(TITLE)] (: all documents where TITLE exists or not exists :) doc()/DOC[AGENCY='EFE' and TITLE=''] (: zero results!!! :) Really, we'd like to define a constraint in search api and to write something like: search:search('title:null age:efe) Or otherwise a additionat-query with cts:query code. Regards, Mariano Grau mgrau @ grupojoly.com Dpto. Sistemas Grupo Joly _______________________________________________ General mailing list [email protected]<mailto:[email protected]>http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
