Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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