You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Liz Glasser <lg...@zargis.com> on 2010/07/23 17:43:15 UTC

Query Help

I have a ton of records in my xindice database that look like:
<MyRootElement myId="...">.....</MyRootElement>

I need the most efficient way to get a list of all values for myId. How 
can I best do this?

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.

Thanks in advance,

Liz Glasser

Re: Query Help

Posted by Liz Glasser <lg...@zargis.com>.
Thank you! I had been trying /MyRootElement/@MyId[@MyFlag=1] which 
obviously was wrong.

Liz

Vadim Gritsenko wrote:
> 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=1? That's really what I ultimately want.
>>     
>
> That can easily be done with XPath: /MyRootElement[@MyFlag = 1]/@myId
>
> Just pass this XPath query to Xindice:
>
>   xindice xpath -c /db/my/collection -q "/MyRootElement[@MyFlag = 1]/@myId"
>
>
> Vadim
>
>
>   
>> Liz
>>
>> Vadim Gritsenko wrote:
>>     
>>> 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="...">.....</MyRootElement>
>>>>
>>>> I need the most efficient way to get a list of all values for myId. How can I best do this?
>>>>
>>>> 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="http://xml.apache.org/xindice/Query" myId="value" xq:col="/db/my/collection" xq:key="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
>>>
>>>
>>>
>>>  
>>>       
>
>
>
>   


Re: Query Help

Posted by Vadim Gritsenko <va...@reverycodes.com>.
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=1? That's really what I ultimately want.

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

Just pass this XPath query to Xindice:

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


Vadim


> Liz
> 
> Vadim Gritsenko wrote:
>> 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="...">.....</MyRootElement>
>>> 
>>> I need the most efficient way to get a list of all values for myId. How can I best do this?
>>> 
>>> 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="http://xml.apache.org/xindice/Query" myId="value" xq:col="/db/my/collection" xq:key="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
>> 
>> 
>> 
>>  
> 


Re: Query Help

Posted by Liz Glasser <lg...@zargis.com>.
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=1? That's really what I ultimately want.

Liz

Vadim Gritsenko wrote:
> 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="...">.....</MyRootElement>
>>
>> I need the most efficient way to get a list of all values for myId. How can I best do this?
>>
>> 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="http://xml.apache.org/xindice/Query" myId="value" xq:col="/db/my/collection" xq:key="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
>
>
>
>   


Re: Query Help

Posted by Vadim Gritsenko <va...@reverycodes.com>.
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="...">.....</MyRootElement>
> 
> I need the most efficient way to get a list of all values for myId. How can I best do this?
> 
> 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="http://xml.apache.org/xindice/Query" myId="value" xq:col="/db/my/collection" xq:key="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