[MarkLogic Dev General] on the topic of cts:search
Alan Darnell
alan.darnell at utoronto.ca
Mon Dec 10 17:48:25 PST 2007
Thanks Danny. I was under the misunderstanding that the first
expression in cts:search limited the search to the element specified
in the expression and not that element and all others beneath it.
Thanks for clearing this up.
Alan
On 10-Dec-07, at 5:21 PM, Danny Sokolsky wrote:
> Hi Alan,
>
> The quick answer to your question is yes, the first parameter to
> cts:search does limit the part of the document that is searched.
>
> Here is a slightly longer answer.
>
> The first parameter to cts:search specifies the nodes under which the
> search is performed. So when you specify fn:doc(), that expression
> returns all of the documents in the database, and that is what is
> searched. When you specify fn:doc()/title, that says to search under
> title elements that occur at the root of a document. cts:search
> searches through all descendants of what is specified in the first
> parameter (that is, for doc()/title, it searches through
> *everything* at
> and below the root title element).
>
> The first parameter also specifies the nodes returned from cts:search.
> So when you specify fn:doc(), it returns document nodes, when you
> specify fn:doc()/title, it returns title nodes. If you searched on
> /title/foo/bar, it would return bar elements where the path is
> /title/foo/bar.
>
> The second parameter constrains the nodes specified in the first
> parameter by a cts:query. If the cts:query on a node returns true, it
> returns the node, if it returns false, it does not return the node.
> So
> with the example you had:
>
> cts:search(doc()/title,
> cts:element-word-query(xs:QName("abstract"),"water"))
>
> that returns title elements that are the root element of a document,
> where somewhere under that title element there exists an abstract
> element that contains the word "water". In other words, you are
> searching the title elements, but only returning ones that satisfy the
> cts:query expression (ones that have "water" in an abstract element).
>
> As an aside, what I said above describes the behavior for search with
> the default "filtered" option. If you do unfiltered search, it
> returns
> the result directly from the index resolution phase of query
> processing.
> Filtered search verifies (on the evaluator node) that the search
> actually matches the search--unfiltered search skips this step.
> Depending on your fragmentation, that also affects unfiltered search
> results.
>
> Hope that helps,
> -Danny
>
> -----Original Message-----
> From: general-bounces at developer.marklogic.com
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Alan
> Darnell
> Sent: Monday, December 10, 2007 1:16 PM
> To: General Mark Logic Developer Discussion
> Subject: [MarkLogic Dev General] on the topic of cts:search
>
> I'm unclear about the effect of the first parameter expression in
> cts:search.
>
> I think I understand that if I do something like
>
> cts:search(doc(),"water")
>
> I'm doing a cts:word-query search for water and the search is run
> against the whole document.
>
> If I do something like
>
> cts:search(doc()/title,"water")
>
> I've limited the word search to just the title element (I think). At
> least only documents with the word in the title seem to come back.
>
> But what is going on if I do something like
>
> cts:search(doc()/title, cts:element-word-
> query(xs:QName("abstract"),"water"))
>
> I think I'm only searching the abstract element and I think the first
> parameter to cts:search is limiting only the element that gets
> returned, but is that correct? Does the first parameter to cts:search
> effect what part of the document is being searched?
>
> Alan
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
More information about the General
mailing list