Solved

Full text search with XQuery but exclude one node in the document

Posted on 2006-11-15
5
249 Views
Last Modified: 2012-06-21
Hi experts,

right now I'm facing a problem I can't solve. Let's say I have two XML documents in the collection in the eXist XML database. These documents look like follows:

<PartnerData>
    <MetaData>
        <DataGUID>PADA7b54de877629135d4c8a6fceb2542244</DataGUID>
        <History>
            <Created>
                <Timestamp>2006-11-14T11:36:45+01:00</Timestamp>
                <User>
                    <IdRefObjectText>John Doe</IdRefObjectText>
                    <IdRefVersion/>
                </User>
            </Created>
        </History>
    </MetaData>
    <Name>John</Name>
    <Firstname>Miller</Firstname>
</PartnerData>

and another one let's say

<PartnerData>
    <MetaData>
        <DataGUID>PADA7b54de877629135d4c8a6fceb2542244</DataGUID>
        <History>
            <Created>
                <Timestamp>2006-11-14T11:36:45+01:00</Timestamp>
                <User>
                    <IdRefObjectText>John Doe</IdRefObjectText>
                    <IdRefVersion/>
                </User>
            </Created>
        </History>
    </MetaData>
    <Name>Test</Name>
    <Firstname>Test</Firstname>
</PartnerData>


Now I would like to find a that has "john" somewhere in the document. I use the following XQuery syntax

for $searchResult in collection("partnerdata")/PartnerData//*[.&="*john*"]
return $searchResult

The problem with this is, that this search call returns both documents, because the engine finds john in both documents. What I need is the search engine to exclude the MetaData node with all the sub nodes.

Do you have any idea how to do that? It's really important.

Best regards
Mike
0
Comment
Question by:priv53
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17945691
Hi priv53,

try something like this

for $searchResult in collection("partnerdata")/PartnerData//*[not(name(ancestor-or-self::*) = 'MetaData)][.&="*john*"]
return $searchResult

It will be more efficient though to name the nodes the processor actually has to look in

for $searchResult in collection("partnerdata")/PartnerData//*[name() = 'Name' | name() = 'Firstname'][.&="*john*"]
return $searchResult


Cheers!
0
 

Author Comment

by:priv53
ID: 17945741
Hi Gertone

if I try your first solution, I receive

An exception occurred during query execution: The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: name($a as node?) xs:string?. Expected cardinality: zero or one, got 2.

Do you have an idea why?

Thx
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 17946083
priv53,
> Do you have an idea why?

yes, because my earlier XPath s#@cked :-)

I made the metadata bit too complex
Try this

for $searchResult in collection("partnerdata")/PartnerData//*[not(ancestor-or-self::MetaData)][.&="*john*"]
return $searchResult

Still it looks up the tree
If you have a non optimised XPath engine
this might become a burden on a huge dataset

cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question