[MarkLogic Dev General] search for non-existing elements
Glidden, Douglass A
Douglass.A.Glidden at boeing.com
Thu Nov 19 13:25:12 PST 2009
A word of warning, unless you're 100% certain that your indices are set up such that the query inside the cts:not-query will _never_ need filtering, cts:not-query can miss correct results. The cts:not-query is one of the only queries that can err in failing to return positive matches (i.e. it gives false negatives instead of false positives).
Not saying you can't use it, just be very careful...
The Boeing Company
Douglass.A.Glidden at boeing.com
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Geert Josten
Sent: Thursday, November 19, 2009 16:16
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] search for non-existing elements
> Each conceptDef is a fragment (its parent, terminology is a fragment
> Root) I rewrote it as this :
I don't think that defining 'terminology' as fragment Root puts each conceptDef in its own fragment. Actually, as 'terminology' seems to be the root element of your document, it would be putting the whole document in a fragment, which isn't very helpful.
> My guess is that the non-existance of elements is not
> indexed. I would think there would be some way in ML to
> index that information but I cant find it.
It is pretty difficult to put something in an index that isn't there.. :-)
> Instead what I did was pre-process the XML file to generate a 'tree
> structure' of the elements containing just the id's.
> <concept id="1">
> <concept id="2">
> <concept id="3"/>
> <concept id="4"/>
> This tree xml is 4MB instead of 50MB and processing through it to find
> out what things have child elements is almost instant.
> Then I cross reference back to the main XML using the id and thats
> instant as well.
Yes, this works not too bad, unless there are lot's of updates which means updating this tree each time as well.
Note: you could store this tree in the document properties if you like.
> SO while this isnt blocking me, I'm curious. Is there a way to tell
> ML to index the non existence of elements or attributes ? I would
> think thats a very common search. I tried searching for word matches
> with the empty text but that didnt work.
Well.. There is the cts:not-query. But it usually doesn't work as expected. The documentation states:
"The cts:not-query constructor is fragment-based, so it returns true only if the specified query does not produce a match anywhere in a fragment."
It is best to read the full explanation: http://developer.marklogic.com/pubs/4.1/apidocs/cts-query.html#cts:not-query
A bit of a guess, but it might work if you would do the following (untested!):
Add a fragment root for 'conceptDef', instead of 'terminology', otherwise the cts:not-query won't help at all. Perhaps you need to reindex as well.
Drs. G.P.H. Josten
Source of Innovation
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
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.
General mailing list
General at developer.marklogic.com
More information about the General