Re: Query Help

Vadim Gritsenko <[email protected]> Mon, 26 Jul 2010 20:51:44 -0400
Newsgroups gmane.text.xml.xindice.user
Message-ID <[email protected]>
On Jul 26, 2010, at 9:04 AM, Liz Glasser wrote:

> Thank you. I have it working now. What if I have two attributes on the =
MyElement named MyId and MyFlag and I want to get the MyId values for =
all entries where MyFlag=3D1? That's really what I ultimately want.

That can easily be done with XPath: /MyRootElement[@MyFlag =3D 1]/@myId

Just pass this XPath query to Xindice:

  xindice xpath -c /db/my/collection -q "/MyRootElement[@MyFlag =3D =
1]/@myId"


Vadim


> Liz
>=20
> Vadim Gritsenko wrote:
>> On Jul 23, 2010, at 11:43 AM, Liz Glasser wrote:
>>=20
>> =20
>>> 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.
>>>   =20
>>=20
>> Hey Liz,
>>=20
>> 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):
>>=20
>>  xindice xpath -c /db/my/collection -q /MyRootElement/@myId
>>=20
>> Results should look like:
>>=20
>>  <xq:result xmlns:xq=3D"http://xml.apache.org/xindice/Query" =
myId=3D"value" xq:col=3D"/db/my/collection" xq:key=3D"MyDocument1" />
>>  ...
>>=20
>>=20
>> 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:
>>=20
>>  xindice add_indexer -c /db/my/collection -n MyRootElementMyId -p =
MyRootElement@ myId
>>=20
>>=20
>> 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.
>>=20
>> Hope that helps.
>>=20
>> Vadim
>>=20
>>=20
>>=20
>> =20
>=20