Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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