​This is the full function. The $doctype corresponds to the root element of the file. So if I have files that are concepts and tasks and I say search in doctype concept, no task will be returned.

<concept><title>concept blah</title><conbody>More blah</conbody></concept>
<task><title>task blah</title><taskbody>A bunch of steps...</taskbody></task>

*.* happens when the keyword section of the query is an empty string. We assume that the user wants all results for the specified doctype. If no doctype (empty string) is specified, we assume they want the entire library.

In 8.5.2, I get 0 item found when I search for keywords = ''

declare

​ ​
function search:search-all($doctype as xs:string, $keywords as xs:string, $operator as xs:string, $lang as xs:string) as node(){
   let $keywords :=
      if (normalize-space($keywords)='')
      then '*'
      else $keywords
   let $words := tokenize(normalize-space($keywords), '&#32;')
   let $wild-words := for $word in $words
                      return concat($word, '.*')
   let $first-words := if (count($words) > 1)
                       then string-join($words[position()!=last()], '&#32;')
                       else ''
   let $last-keyword := tokenize(normalize-space($keywords), '&#32;')[last()]
   let $wild-keywords := if (string-length($last-keyword) > 3)
                         then concat($first-words, '&#32;', $last-keyword, '.*')
                         else ''
   let $all-wild-keywords := tokenize(normalize-space($wild-keywords), '&#32;')

   let $search-subset :=
      if ($doctype = '')
      then db:open($lang)/*
      else db:open($lang)/*[name()=$doctype]

   let $search-result :=
      if ($operator = 'and')
      then $search-subset[(descendant::title[1] contains text ({$wild-words} all using wildcards weight {2})) or (. contains text ({$wild-words} all using wildcards weight {0.5}))]
      else $search-subset[(descendant::title[1] contains text ({$wild-words} any using wildcards weight {2})) or (. contains text ({$wild-words} any using wildcards weight {0.5}))]

   let $ordered-results := for $x score $s in $search-result
                           order by $s descending, $x/title ascending
                           return $x
   (: Adding no result in options because Safari 9.1.1 doesn't always respond to :empty
      no longer being empty after a $.get :)
   return <div>
            <div style="width:100%;">
               <span style="display:inline-block; font-style:italic; text-align:right; width:100%;">{count($ordered-results)}&#160;{
                 
​​
if (count($ordered-results) < 2)
                  then resources:get-app-string('item-found', $lang)
                  else resources:get-app-string('items-found', $lang)
               }</span>
            </div>
            {search:format-result-docs-as-table($ordered-results, $lang)}
           </div>

};