On Thu, 2013-01-10 at 16:13 +0000, Mayer, Jonathan wrote:

> Running:
> 
> XQUERY db:open('project', 'Links.xml')
> 
> From the command line displays the file in 4.5 seconds

Is this on a 1MHz 286? :D

How many megabytes is the file?

The usual trick is to put the document in the database so you don't need
to read it off disk each time.

http://www.fromoldbooks.org/ connects to a local basex server for the
keyword "tag cloud" and it's fast enough that I have not bothered to use
memcached to speed it up. The XML file is a little under 6 megabytes,
though, so not very large. Here's the code I use. The element and
attribute indexes are properly titillated, er, turned on, but I have not
measured whether that makes a difference.


include("Search/BaseXClient.php");
try {
  $session = new Session("localhost", 1994, "socks", "black");
  $session->execute("open rdf");
  $session->execute("set SERIALIZER
         method=xhtml,omit-xml-declaration=yes,indent=no");
  echo $session->execute('xquery
      <div class="tagcloud">{
          let $kw := /cache/kwlist/kw,
          $max := math:sqrt(max(
            for $e in $kw return xs:integer($e/@count)
          ))
          return
              for $i in /cache/kwlist/kw
              let $freq :=
                  xs:integer(10 * math:sqrt($i/@count) div $max)
              where xs:integer($i/@count) ge 10
              order by $i/@what
              return (
                <a
                  class="tag freq{$freq}"
                  title="items: {$i/@count}"
                  href="/Search/?kw={translate($i/@what, " ",
"+")};fp=1"
                  >
                {replace(xs:string($i/@what), "^letter([a-z])$", "letter
$1")}
                </a>,
                "&#xa;"
              )
    }</div>
  ');
  // close session
  $session->close();

} catch (Exception $e) {
  // print exception
  print $e->getMessage();
}


-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

Reply via email to