To optimize a query like this, first identify the expressions that can't
use index lookups. Then modify the query or its context so that the work
is pre-calculated within the indexes.
Here, the unindexed parts are both in the where-clause: meta:author[1]
and count(meta:author). Both are susceptible to optimization by
enriching the XML.
The author-count could be in the document as meta:authors/@count -
similarly, the primary author could be distinguished as
meta:primary-author. When querying both types of author you could either
repeat the value or use something like this:
cts:element-value-query(
(xs:QName('meta:primaryAuthor'), xs:QName('meta:author')),
$value, $options )
-- Mike
On 2010-05-19 08:10, Declan Newman wrote:
> Hello,
>
> I'm trying to create a query with several parameters, including one
> which is a count of elements and another that needs to only search on
> the first element value.
>
> I am currently checking for these outside of the query itself, but it
> would be nice (and more optimised?) to have everything inside the query
> itself. (Or perhaps this is a wrong assumption?)
>
> Any thoughts as to how this could be done? Or am I barking up the wrong
> tree?
>
> So far, I have the following:
>
> xquery version "1.0-ml";
> declare namespace meta="http://semantico.com/meta";
>
> declare variable $eissn := '1476-4687';
> declare variable $issn := '1422-468X';
> declare variable $volume := '460';
> declare variable $authorLastName := fn:lower-case('Tung');
> declare variable $noOfAuthors := 6;
>
>
> declare function local:finder() as node()* {
>
> let $eissnstrip := fn:replace($eissn, '-', '')
> let $issnstrip := fn:replace($issn, '-', '')
> for $meta in cts:search(/record/metadata,
> cts:and-query((
>
> cts:or-query((
> cts:element-value-query(
> xs:QName("meta:eissn"),
> $eissn, ("punctuation-insensitive", "case-insensitive")),
> cts:element-value-query(
> xs:QName("meta:eissn"),
> $eissnstrip, ("punctuation-insensitive", "case-insensitive")),
> cts:element-value-query(
> xs:QName("meta:issn"),
> $issn, ("punctuation-insensitive", "case-insensitive")),
> cts:element-value-query(
> xs:QName("meta:issn"),
> $issnstrip, ("punctuation-insensitive", "case-insensitive"))
> )),
>
> cts:element-value-query(
> xs:QName("meta:volume"),
> $volume)
> ))
> )
> where fn:lower-case($meta/meta:authors/meta:author[1]/meta:last) =
> $authorLastName
> and count($meta/meta:authors/meta:author) = $noOfAuthors
> return
> $meta
> };
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general