Database Reference
In-Depth Information
We're almost done. After defining a new collection, you'll have to reindex. Use the
collection browser to go to /db/apps/exist101/data and click “Reindex collection” (the
second button from the left). This will take a few seconds. After this initial reindex
you'll never have to do any manual maintenance again; eXist now knows the index
and will keep it up to date for you when the dataset changes.
Our indexed search is ready to go. Try it by searching on fantasy again, and you
should now see the same results as in our straight XQuery search ( Figure 3-7 ).
So, have we gained anything? Yes, we have!
• Search on FANTASY : the search is now case-insensitive.
• Search on fantasy horatio . You'll get a long list with lines in which one or both of
the two words are present.
• Search on fantasy AND horatio . Now there is only one line: the only one with
both words.
• But perhaps most importantly: this search is faster (although you might not
notice on modern hardware with this small dataset), and it scales! Add more
plays, and it will stay fast.
This was the just tip of the iceberg in terms of what you can do with indexes. For
example, in “Full-Text Index and KWIC Example” on page 285 , you'll learn about sort‐
ing by relevance and how to use eXist's “keywords in context” feature to highlight the
matching words in the search results. Adding such capabilities to our eXist 101 appli‐
cation is not difficult once you have progressed further through the topic, and we'll
leave this to you as an independent exercise.
Creating a Log
The last capability we're going to add to our application is having it maintain a log‐
file, showing you how you can update the database from XQuery. Since we'll proba‐
bly want to use this feature from more than one XQuery script, we're going to put the
code for it into an XQuery module and show you a little about modularization. While
testing, we'll also run into some interesting security problems and show you how to
solve them.
By way of preparation, create the collection /db/apps/exist101/log to hold our log
information.
We require our logging to write strings to a logfile and add a timestamp. If the logfile
does not exist, it should be created. The logfile should be easy to use and callable
from all our existing XQuery scripts without code duplication.
Search WWH ::




Custom Search