searchDocByAuthor.hq 1.06 KB
Newer Older
1
2
(: This script will return documents by searching its author :)
(: We can assign a Regular Expression to the variable $author :)
simei.yin's avatar
simei.yin committed
3
(: For example, $name := '^Baptiste Montangé$', to search for an exact name:)
4
(: For example, $name := 'Montangé', to search for documents whose author named Coutant:)
simei.yin's avatar
simei.yin committed
5
(: Remark : case and accents in author's name have been taken care of :)
simei.yin's avatar
simei.yin committed
6

7
8
declare function local:searchDocByAuthor($name as xs:string, $docs as node()*) as node()*
{
simei.yin's avatar
simei.yin committed
9
  let $name_noAcc := translate($name, 'áàâäéèêëíìîïóòôöúùûüABCDEFGHIJKLMNOPQRSTUVWXYZ','aaaaeeeeiiiioooouuuuabcdefghijklmnopqrstuvwxyz')
10
  for $doc in $docs
11
12
13
  return
    for $author in $doc/authors/author
    let $titre := $doc/titre
simei.yin's avatar
simei.yin committed
14
    let $author_noAcc := translate($author, 'áàâäéèêëíìîïóòôöúùûüABCDEFGHIJKLMNOPQRSTUVWXYZ','aaaaeeeeiiiioooouuuuabcdefghijklmnopqrstuvwxyz')
15
16
17
    where matches($author_noAcc, $name_noAcc)
    group by $titre (: Avoid duplications of documents by their titre:)
    return $doc
18
19
20
21
};

(: Example :)
local:searchDocByAuthor('Montangé', //document)