[MarkLogic Dev General] How to get accurate fragment counts using xdmp:estimate when the QName is a variable

Darin McBeath ddmcbeath at yahoo.com
Wed Sep 15 08:58:07 PDT 2010


Thanks Mike.

I had actually tried a slight variant of what you suggested below (removed the 
string()) so that the query looked like the following:

xdmp:estimate(//*[node-name(.)=$eQName and @*[node-name(.) = $aQName] = $value])

But, this also didn't work ... returned me a count for every fragment in the DB.

However, I tried what you suggested ... essentially removing the 'and' above 
with another predicate [ ] and I now get the desired result.

So, the following is the answer to my question.

xdmp:estimate(//*[node-name(.)=$eQName][@*[node-name(.) = $aQName] = $value])

Thanks again.

Darin.



________________________________
From: Michael Blakeley <michael.blakeley at marklogic.com>
To: General Mark Logic Developer Discussion <general at developer.marklogic.com>
Cc: "McBeath, Darin W (ELS-STL)" <D.McBeath at elsevier.com>
Sent: Wed, September 15, 2010 11:41:45 AM
Subject: Re: [MarkLogic Dev General] How to get accurate fragment counts using 
xdmp:estimate when the QName is a variable

Darin, have you tried using xdmp:query-trace()? Which version of the 
server are you using?

I suspect that the eQName is working, but the unnecessary string() call 
is a problem. Try this:

xdmp:estimate(
   //*
     [node-name(.)=$eQName]
     [@*[node-name(.) = $aQName] = $value] )

Trace:

2010-09-15 08:36:55.576 Info: Docs: line 6: Analyzing path: 
fn:collection()/descendant::foo[@bar = "baz"]
2010-09-15 08:36:55.576 Info: Docs: line 6: Step 1 is searchable: 
fn:collection()
2010-09-15 08:36:55.576 Info: Docs: line 6: Step 2 is searchable: 
descendant::foo[@bar = "baz"]
2010-09-15 08:36:55.576 Info: Docs: line 6: Path is fully searchable.
2010-09-15 08:36:55.576 Info: Docs: line 6: Gathering constraints.
2010-09-15 08:36:55.576 Info: Docs: line 6: Comparison contributed hash 
value constraint: foo/@bar = "baz"
2010-09-15 08:36:55.576 Info: Docs: line 6: Step 2 predicate 1 
contributed 1 constraint: @bar = "baz"
2010-09-15 08:36:55.576 Info: Docs: line 6: Comparison contributed hash 
value constraint: foo/@bar = "baz"
2010-09-15 08:36:55.576 Info: Docs: line 6: Step 2 predicate 1 
contributed 1 constraint: @bar = "baz"
2010-09-15 08:36:55.576 Info: Docs: line 6: Step 2 contributed 3 
constraints: descendant::foo[@bar = "baz"]
2010-09-15 08:36:55.576 Info: Docs: line 6: Executing search.

-- Mike

On 2010-09-15 08:02, McBeath, Darin W (ELS-STL) wrote:
> Thanks Mary.  That was pretty dumb on my part.  But, I still do have a question 
>based on my more complex example.
>
> Basically, I want to get fragment counts where a fragment contains a given 
>element, attribute, and value for that attribute.  I was thinking that I could 
>do XPath such as below wrapped in a xdmp:estimate.
>
> xdmp:estimate(//*[node-name(.)=$eQName and string(./@*[node-name(.) = $aQName]) 
>= $value])
>
> But, this always seems to return me the number of fragments in the DB.  I did 
>verify that
>
> //*[node-name(.)=$eQName and string(./@*[node-name(.) = $aQName]) = $value]
>
> Only returns the nodes which I want ... so, unlike last time it would appear 
>the query is at least written correctly.  Perhaps, what I'm trying to do with 
>XPath and an accurate estimate is not currently possible.  I believe that I have 
>the necessary indexes enabled that should support an accurate estmate.
>
> I did verify that something explicit such as the following returns the correct 
>result:
>
> xdmp:estimate(//skos:ConceptScheme[@rdf:about=$value])
>
> This makes me believe that my indexes are configured correctly.
>
> I will likely drop back and try a cts:element-attribute-value-query or 
>xdmp:eval the XPath expression (such as above) ... but, I'm curious as to 
>whether I'm still doing something wrong above or whether this is really not 
>possible.  I also can't really create range indexes on the element/attribute as 
>I'm trying to make this a fairly generic solution whereby one could query on any 
>element/attribute.
>
> Thanks.
>
> Darin.
>
> -----Original Message-----
> From: Mary Holstege [mailto:mary.holstege at marklogic.com]
> Sent: Tuesday, September 14, 2010 4:22 PM
> To: General Mark Logic Developer Discussion; McBeath, Darin W (ELS-STL)
> Subject: Re: [MarkLogic Dev General] How to get accurate fragment counts using 
>xdmp:estimate when the QName is a variable
>
> On Tue, 14 Sep 2010 13:05:58 -0700, McBeath, Darin W (ELS-STL)
> <D.McBeath at elsevier.com>  wrote:
> ...
>> The following query returns me the value I would expect.
>>
>> xdmp:estimate(//skos:ConceptScheme)
>>
>> However, if I have a variable $eQName which is essentially the QName for
>> skos:ConceptScheme
>>
>> xdmp:estimate(//$eQName)
>>
>> returns me every fragment in the DB.
>
> I think the problem is that your query isn't doing what you
> think it is.  It equivalent to //"skos:ConceptScheme",
> the value of which is the string "skos:ConceptScheme" repeated
> for every element in the database.  So the estimate is
> correct, but it isn't what you want.
>
> The only way to get the result you wany from the path is
> something like //*[fn:node-name(.)=$eQName].
>
> //Mary
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20100915/483dfa19/attachment.html 


More information about the General mailing list