Tuesday, August 28, 2007

Querying a MarkLogic Server Collection for a Title List, Plus Performance

The real theme of this post is, "Keep it simple, stupid."

I had a query I was using to generate a list of documents stored in a MarkLogic Server collection. The results were being passed to a web application for use as a title list. I was getting the results I wanted, but the query was taking about 20 seconds to complete and there were fewer than 200 book-length XML files to search. The key line in that query was:
for $i in cts:search(//book, cts:collection-query($myCollection))
I knew there had to be a better way to express this, but I couldn't find anything in the API that helped. Then someone suggested using the built-in XQuery function, collection(). I changed the query to...
for $i in collection($myCollection)/book
...and now the query runs in less than .05 seconds, including some trips down into the structure to grab metadata. That's what I was expecting.

Thanks to the people on the Mark Logic developer email list for helping with this.

No comments: