Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

631 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