Hi John, This can be a little tricky, as it sounds like your "section" elements can mean different things in different places in the document. One approach can be to change your section element names for the ones that have p children to something different, and then search over those. It would be relatively easy to write a transformation in XQuery to do that. Ultimately, this might prove to make your content the most searchable for what you want.
Another approach is to filter out the results that do not have a direct p child from the search results. This will probably be OK if the number of results to filter is small relative to the number of results returned from the search. This might look something like: cts:search(//section, "searchterm")[fn:exists(./p)] You can also search below the section element (//section/p), but that would return p elements. Depending on your content, that might work. There may be a cts:query solution here, too, but without knowing your content very well, it is harder for me to see that. -Danny -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Craft Sent: Tuesday, July 01, 2008 12:58 PM To: General Mark Logic Developer Discussion Subject: [MarkLogic Dev General] Restricting Search Hits To Immediate ParentContainers I am evaluating MarkLogic and have been playing around with the cts:element-query() and cts:element-word-query() expressions. So far, I am having difficulty restricting search results to elements that are direct parents of the elements that contain the search terms. Our content is made up of nested <section> elements and most <section> elements contain <p> elements, which are our containers for paragraph text. The <section> elements contain <title> elements and other information as well. When performing a search, I would like to limit the results to only the <section> elements whose direct <p> children contain search terms. I began by creating the following cts:search() string: cts:search(fn:doc()//section, cts:element-query(xs:QName("section"), cts:element-query(xs:QName("p"), "searchTerm") )) This approach was flawed because the search results included <section> elements that were further up the tree and didn't directly contain <p> elements (or, rather, <p> elements that contained the search terms). My next approach was to use cts:element-word-query() and create an element-word-query-through for the <p> element: cts:search(fn:doc()//section, cts:element-word-query(xs:QName("section"), "searchTerm") ) Again, the search results contain <section> elements that aren't direct parents of <p> elements that contain search terms. The end result is that I end up with a lot of <section> elements that are false positives. I'm beginning to think the path information on the first cts:search() argument may be the problem, but I'm not sure. And if it is the problem, how else can I get search results returned as <section> elements I appreciate any help or suggestions you can provide. Thanks. John Craft _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
