Hi Lanz, You could try to use XPath, but you need some changes to make sure the expression can be optimized.
First, you need a searchable path expression. Searchable expression cannot start with variables, so get the base-uri of $doc and start your path with doc($uri) instead of $doc. Second, I think it is best to add Item as Fragment Root, and replace /Items/Item with //Item. Third thing you should do is replace count() with xdmp:estimate(). The speed of indexes is all about not loading data into memory you don't need. Count forces the processor to load all Items into memory, slowing the count down. Xdmp:estimate just grabs references to fragments from the index and counts those, much quicker. There are some side notes to xdmp:estimate, but this should work I guess. http://developer.marklogic.com/pubs/4.2/apidocs/Ext-4.html#xdmp:estimate Kind regards, Geert > drs. G.P.H. (Geert) Josten Consultant Daidalos BV Hoekeindsehof 1-4 2665 JZ Bleiswijk T +31 (0)10 850 1200 F +31 (0)10 850 1199 mailto:geert.jos...@daidalos.nl http://www.daidalos.nl/ KvK 27164984 De informatie - verzonden in of met dit e-mailbericht - 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: general-boun...@developer.marklogic.com > [mailto:general-boun...@developer.marklogic.com] On Behalf Of Lanz > Sent: vrijdag 12 november 2010 16:19 > To: general > Subject: [MarkLogic Dev General] Optimize time spent for a > query using Element range Index > > Hi All, > > I'm trying to take advantage of 'Element range Index' in a query but > can't find how... > > Here is my context : > <Items> > <Item> > <Productid>72764</Productid> > <ItemType>Article</ItemType> > <DOI>budget-10xxxyyy</DOI> > <Element>C</Element> > <VersionCode>E</VersionCode> > <Theme> > <ProductId>72764</ProductId> > <ThemeCode>37</ThemeCode> > </Theme> > <Theme> > <ProductId>72764</ProductId> > <ThemeCode>39</ThemeCode> > </Theme> > </Item> > <Item> > <Productid>72692</Productid> > <ItemType>Book</ItemType> > <DOI>budget-10-yyyyyxxxx</DOI> > <Element>C</Element> > <VersionCode>E</VersionCode> > <Theme> > <ProductId>72692</ProductId> > <ThemeCode>37</ThemeCode> > </Theme> > <Theme> > <ProductId>72692</ProductId> > <ThemeCode>39</ThemeCode> > </Theme> > </Item> > .... > </Items> > > I want to get statistics of how many Items I have for a given > ThemeCode by ItemType (ie for the ThemeCode '37' : I have 53 items of > ItemType 'Article' for the ThemeCode '37' and 89 items of ItemType > 'Book' ). > I have the right result using pure Xpath but it takes time : > fn:count($doc/Items/Item[ItemType = $item/@name and Theme/ThemeCode = > $themeId]) (where $doc is my searched document, $item/@name is the > name of itemtype in a loop and $themeId the selected themeCode) > I have created 2 Element range Index, one for element ItemType and one > for element ThemeCode. How can I get same statistics using 'nested' > Element range Index and cts:and-query (or other syntax ?) ? > > Any suggestions would be appreciated, many thanks > Lanz > _______________________________________________ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general