Danny,

My app basically allows a user to input multiple optional query
parameters. I then create a cts:query with those parameters which gets
passed to a cts:search to identify matching documents. The documents
are then typically summarized and returned. I'll also wind up reusing
the cts:query that I created to do odd things to try to improve my
performance(heavy use of cts:element-values and cts:uris). I've found
that using the cts:query results in cleaner code.

I don't think the other techniques you described will work for me
because I need to use my query to search over the entire document or
for lexicon queries.

I hope this makes sense,
Jake

On Dec 12, 2007 12:55 PM, Danny Sokolsky <[EMAIL PROTECTED]> wrote:
> Hi Jake,
>
> You are correct, you cannot express that with only a cts:query;  you
> also need to use the first arg to cts:search.  The cts:query
> constructors allow you to do many things, even most things, but not all
> things.  As I said, you can still perform this search a number of ways,
> two of which are below.
>
> Is there some reason the other ways won't work for you?
>
> -Danny
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jacob
> Meushaw
>
> Sent: Wednesday, December 12, 2007 7:26 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] simple cts:search question
>
> Danny,
>
> Thanks for the response. This is a serious bummer for me. I guess I
> was incorrectly under the impression that I could successfully
> recreate any xPath using cts:query constructors. What I'm hearing is
> that I CAN NOT write a cts:query that says:
>
> Find a document that:
>    has an element "docname" with a value of "cars"
>       and
>    has an element "car" with a value of "m3" and an attribute "color" =
> "green"
>
> Is this correct?
>
> Thanks,
> Jake
>
> On Dec 10, 2007 12:57 PM, Danny Sokolsky <[EMAIL PROTECTED]>
> wrote:
> > Hi Jacob,
> >
> > Your query will not work with an element-query constructor.  The
> > element-query constructor searches through all text-node descendants
> of
> > the specified element; it does not search through attribute nodes.
> >
> > Using the first parameter to cts:search, you can test for both the
> > attribute and the element value you want.
> >
> > The two methods I suggested earlier should work, I think.  For
> example:
> >
> > cts:search(/mydoc/data/carList/car,
> >   cts:and-query((
> >     cts:element-value-query(xs:QName("car"), "m3"),
> >
> cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
> > "blue")
> >   ))
> > )
> >
> > This does not return the node (because it is searching under the car
> > element).
> >
> > This was does return the node:
> >
> > cts:search(/mydoc/data/carList/car,
> >   cts:and-query((
> >     cts:element-value-query(xs:QName("car"), "m3"),
> >
> cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
> > "green")
> >   ))
> > )
> >
> > If you want to get the whole document, you can then use XPath or a
> > function to get there, as follows:
> >
> > cts:search(/mydoc/data/carList/car,
> >   cts:and-query((
> >     cts:element-value-query(xs:QName("car"), "m3"),
> >
> cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
> > "green")
> >   ))
> > )/fn:root()
> >
> > Does this get you what you need?
> >
> > -Danny
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Jacob
> > Meushaw
> > Sent: Monday, December 10, 2007 8:06 AM
> > To: General Mark Logic Developer Discussion
> > Subject: Re: [MarkLogic Dev General] simple cts:search question
> >
> >
> > I think my example wasn't sufficient to explain the problem fully.
> > Below is some code that does a better job of showing what I'm doing
> > and what my problem is.
> >
> > (: create a test document :)
> >
> > let $testDoc :=
> >
> > <mydoc>
> >     <properties>
> >         <docname>cars</docname>
> >     </properties>
> >     <data>
> >         <carList>
> >             <car color="green">M3</car>
> >             <car color="blue">beetle</car>
> >             <car color="yellow">fiat</car>
> >             <car color="red">911</car>
> >         </carList>
> >     </data>
> > </mydoc>
> >
> > return xdmp:document-insert("mytest.xml",$testDoc,(),("test"))
> >
> >
> > (: cts search for docs with a docname of "cars" and containing a blue
> > M3 in it's car list :)
> > (: This query returns the document because there is a car with a color
> > of blue and a car with a name of M3. :)
> > (: This is not the behavior I'm looking for. I want it to fail because
> > the M3 is not blue. :)
> >
> > let $query := cts:and-query((
> >
> >
> cts:element-query(xs:QName("properties"),cts:element-value-query(xs:QNam
> > e("docname"),"cars")),
> >     cts:element-query(xs:QName("carList"),
> >         cts:and-query((
> >
> >
> >
> cts:element-attribute-value-query(xs:QName("car"),QName("","color"),"blu
> > e"),
> >             cts:element-value-query(xs:QName("car"),"M3")
> >         ))
> >     )
> > ))
> >
> > return cts:search(collection("test")/mydoc,$query)
> >
> >
> >
> > On Dec 6, 2007 1:01 PM, Danny Sokolsky <[EMAIL PROTECTED]>
> wrote:
> > > Thanks Mike, you are absolutely correct.  Sorry 'bout that...
> > >
> > > So here are a few ways you might do this:
> > >
> > > 1) with XPath and cts:contains
> > >
> > > //car[cts:contains(., cts:and-query((
> > >      cts:element-value-query(xs:QName("car"), "m3"),
> > >      cts:element-attribute-value-query(xs:QName("car"),
> > > xs:QName("color"),
> > >                     "green"))))]
> > >
> > > 2) with cts:search
> > >
> > > cts:search(/carList/car,
> > >   cts:and-query((
> > >     cts:element-value-query(xs:QName("car"), "m3"),
> > >
> > cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
> > > "green")
> > >   ))
> > > )
> > >
> > > Does that get you what you are looking for?
> > >
> > > -Danny
> > >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > >
> > > [mailto:[EMAIL PROTECTED] On Behalf Of Mike
> > > Sokolov
> > > Sent: Thursday, December 06, 2007 9:42 AM
> > > To: General Mark Logic Developer Discussion
> > > Subject: Re: [MarkLogic Dev General] simple cts:search question
> > >
> > > There might be something about the scope of the query (first arg to
> > > cts:search), but in my experience cts:element-query doesn't include
> > > itself in its scope, only its descendants, so I don't think the
> change
> > > you are suggesting will solve his problem?  I put in a change
> request
> > to
> > >
> > > correct that: it seems like the behavior everyone expects.
> > >
> > > -Mike
> > >
> > > Danny Sokolsky wrote:
> > > > I think the problem is that the cts:element-query is on the
> > "carList"
> > > > element, and it should be on the "car" element.
> > > >
> > > > -Danny
> > > >
> > > > -----Original Message-----
> > > > From: [EMAIL PROTECTED]
> > > > [mailto:[EMAIL PROTECTED] On Behalf Of
> Jacob
> > > > Meushaw
> > > > Sent: Thursday, December 06, 2007 8:58 AM
> > > > To: [email protected]
> > > > Subject: [MarkLogic Dev General] simple cts:search question
> > > >
> > > > Hello All,
> > > >
> > > > I'm stumped on what must be a very simple cts:search question.
> > > >
> > > > I'm trying to identify documents in my database using cts:search
> > which
> > > > match a set of parameters. The case I'm stumped on is where I want
> > to
> > > > match on both the value of the element as well as one of it's
> > > > attributes.
> > > >
> > > > For example a document might contain:
> > > >
> > > > <carList>
> > > >      <car color="green">M3</car>
> > > >      <car color="blue">beetle</car>
> > > >      <car color="yellow">fiat</car>
> > > >      <car color="red">911</car>
> > > > </carList>
> > > >
> > > > I can't seem to figure out how to construct a cts query that
> matches
> > > > both the attribute value and the element value of the same
> element:
> > > >
> > > > cts:element-query(
> > > >     xs:QName("carList"),
> > > >     cts:and-query((
> > > >
> > > >
> > >
> >
> cts:element-attribute-value-query(xs:QName("car"),QName("","color"),"blu
> > > > e"),
> > > >         cts:element-value-query(xs:QName("car"),"M3")
> > > >     ))
> > > > )
> > > >
> > > > This incorrectly matches the example. The M3 is not blue.
> > > >
> > > > Hopefully this makes sense.
> > > >
> > > > Any ideas?
> > > >
> > > > Thanks,
> > > > Jake
> > > > _______________________________________________
> > > > General mailing list
> > > > [email protected]
> > > > http://xqzone.com/mailman/listinfo/general
> > > > _______________________________________________
> > > > General mailing list
> > > > [email protected]
> > > > http://xqzone.com/mailman/listinfo/general
> > > >
> > > _______________________________________________
> > > General mailing list
> > > [email protected]
> > > http://xqzone.com/mailman/listinfo/general
> > > _______________________________________________
> > > General mailing list
> > > [email protected]
> > > http://xqzone.com/mailman/listinfo/general
> > >
> > _______________________________________________
> > General mailing list
> > [email protected]
> > http://xqzone.com/mailman/listinfo/general
> > _______________________________________________
> > General mailing list
> > [email protected]
> > http://xqzone.com/mailman/listinfo/general
> >
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to