Re: Query Help
Vadim Gritsenko <[email protected]> Sun, 25 Jul 2010 18:35:56 -0400
| Newsgroups | gmane.text.xml.xindice.user |
|---|---|
| Message-ID | <[email protected]> |
On Jul 23, 2010, at 11:43 AM, Liz Glasser wrote: > I have a ton of records in my xindice database that look like: > <MyRootElement myId=3D"...">.....</MyRootElement> >=20 > I need the most efficient way to get a list of all values for myId. = How can I best do this? >=20 > Basically if this was a relational database and I had a table called = MyRootElement, I'd do "select myId from MyRootElement". I need a xindice = equivalent. Hey Liz, The query you are looking for is "/MyRootElement/@myId". Using command = line you can query it like this (replace /db/my/collection with path to = your collection): xindice xpath -c /db/my/collection -q /MyRootElement/@myId Results should look like: <xq:result xmlns:xq=3D"http://xml.apache.org/xindice/Query" = myId=3D"value" xq:col=3D"/db/my/collection" xq:key=3D"MyDocument1" /> ... Now, if only some % of documents in this collection contain this root = element/attribute, then you can speed that query up by build an index on = the element/attribute pair. Index will allow query engine to skip = documents which do not have that element/attribute pair. Index also = helps if you want to find a document by value of the myId attribute. = Command to build the index looks like: xindice add_indexer -c /db/my/collection -n MyRootElementMyId -p = MyRootElement@ myId OTOH, if all documents have the same structure, then in order to extract = all of the values, query engine will have to iterate through all of the = documents in the collection - and index will be of no help. Hope that helps. Vadim