Search code examples
.netsitecore

Querying a large number of items via Sitecore API


I have read the following question and its answers which may be related:

Does Sitecore use Fast Query automatically?

We have a large gallery built using Sitecore as a backend. There are number of different gallery pages organized in the tree:

Sitecore->Content->MediaLibrary->Gallery->User->{Photos}->{Photo_State}

Where Photo_State is approved, rejected and so forth

Currently to retrieve the images from the database we use GetAncestors() on the "Gallery" part of the tree. This may retrieve thousands of items from the database which are then filtered down using normal .NET filtering practices.

How can we do this in a more efficient way?

We looked at using the Sitecore Fast Query API to do this but I don't currently understand how we could use this to fix our current problem. So our DB queries are:

  • Give me all photos by a user (already handled well/optimally)
  • Give me all photos matching a search - could be handled by @title='%search%' using fast query
  • Give me the first 28 items in a gallery - ??? I don't know how to do this with Fast Query

Any idea how this could be handled optimally through the Sitecore API?


Solution

  • If you potentially have thousands of items you should use Lucene indexes. The Advanced Database Crawler can make this pretty easy to accomplish.