[MarkLogic Dev General] Restricting Search Hits To Immediate Parent
Containers
John Craft
jcraft at jonesmcclure.com
Tue Jul 1 12:57:37 PDT 2008
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
More information about the General
mailing list