Solved

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

Posted on 2006-11-15
5
241 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now