Hi Tim, Shannon,

A cts:query(()) might result in the same as cts:and-query(()). The result of 
the latter is described on 
http://developer.marklogic.com/pubs/4.0/apidocs/cts-query.html#cts:and-query

Personally, but I am not an expert on this matter, I think cts:and-query(()) 
makes more sense. Cts:query seems to suite a quite different purpose. Just let 
your inner if statements return empty sequences, not cts:query(()). You already 
wrapped your if statements inside a cts:and-query, so the cts:query is 
redundant.

You can break down the code even further like this:

Let $publisher-query := if ($publisher ne "") ...
...
Let $combined-query := cts:and-query(($publisher-query, ...))

That way you more clearly combine all sub-queries to one large if that would 
involve more complex combinations of and's, or's, not's etc...

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.


> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Tim Meagher
> Sent: maandag 1 juni 2009 21:48
> To: 'General Mark Logic Developer Discussion'
> Subject: RE: [MarkLogic Dev General] Building cts:search
> querieswithconditional logic
>
> The modularization is a clever idea.  I appreciated your
> mentioning it.
>
>
>
> Tim
>
>
>
> ________________________________
>
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Shannon
> Sent: Monday, June 01, 2009 3:44 PM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Building cts:search
> querieswithconditional logic
>
>
>
> I'm watching to see if ML has an opinion on your () vs.
> cts:query(()) question!  As to the modularized approach, I
> realize your example didn't call for it, and you're probably
> already using that strategy in your production code, but I
> thought I'd mention it in case it would help somebody
> watching the discussion.
>
>
>
> On Jun 1, 2009, at 3:35 PM, Tim Meagher wrote:
>
>
>
>
>
> Hi Shannon,
>
>
>
> Thanks, and yes, I like the modularized approach too!
>
>
>
> Tim
>
>
>
> ________________________________
>
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Shannon
> Sent: Monday, June 01, 2009 3:32 PM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Building cts:search
> queries withconditional logic
>
>
>
> Hi, Tim,
>
>
>
> I've always had great results using simply the empty
> sequence.  I'd be interested to know if there is any
> advantage to using cts:query(()).
>
>
>
> Also, since this is not reflected in your example, just in
> case, I'd like to suggest modularizing it a bit, for far
> easier reading and maintenance--After initializing your
> variables with a series of a let assignments, create a
> combined cts:query by calling other functions, like so:
>
>
>
> let $combined-query := cts:and-query((
>
>             if ($foo) then search:qry1(...) else (),
>
>             if ($bar) then search:qry2(...) else (),
>
> ...
>
> ))
>
>
>
> The search:qry* functions would return a cts:query type --
> basically breaking down each field or fieldset of your form,
> or some other logical grouping, into separate functions.
> Then call cts:search(input(), cts:combined-query)
>
>
>
> Best,
>
>
>
> On Jun 1, 2009, at 3:02 PM, Tim Meagher wrote:
>
>
>
>
>
>
> Hi Folks,
>
>
>
> Is there a preferred way to build a series of cts:search
> constructor functions when using conditional (and/or) logic?
> In the following example I insert a cts:query() if an value
> is blank, in the other I insert an empty sequence:
>
>
>
> cts:search(
>
>   //Record,
>
>   cts:and-query ((
>
>     if ($publisher ne "") then
>
>       cts:element-value-query(xs:QName("Publisher"), $publisher,
>
>         ("case-insensitive", "diacritic-insensitive",
> "punctuation-insensitive")
>
>       )
>
>     else cts:query(),
>
>     if ($title ne "") then
>
>       cts:element-value-query(xs:QName("Title"), $title,
>
>         ("case-insensitive", "diacritic-insensitive",
> "punctuation-insensitive")
>
>       )
>
>     else ()
>
>   ))
>
> )
>
>
>
> Is there a rule for using cts:query() or the empty sequence
> () for dynamically building cts:search constructors?
>
>
>
> Thanks again,
>
>
>
> Tim
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
>
>
>
>
>
> --
> Shannon Scott Shiflett, XML Programmer
> ROTUNDA, The University of Virginia Press PO Box 801079,
> Charlottesville, VA 22904-4318 USA
> Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
> Email: [email protected]   Tel: +1 434 924 4495
> Web: http://rotunda.upress.virginia.edu/
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
>
>
>
>
> --
> Shannon Scott Shiflett, XML Programmer
> ROTUNDA, The University of Virginia Press PO Box 801079,
> Charlottesville, VA 22904-4318 USA
> Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
> Email: [email protected]   Tel: +1 434 924 4495
> Web: http://rotunda.upress.virginia.edu/
>
>
>
>

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to