Index: src/test/java/info/magnolia/cms/core/search/QueryTest.java
===================================================================
--- src/test/java/info/magnolia/cms/core/search/QueryTest.java	(revision 0)
+++ src/test/java/info/magnolia/cms/core/search/QueryTest.java	(revision 0)
@@ -0,0 +1,137 @@
+/**
+ * This file Copyright (c) 2003-2010 Magnolia International
+ * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
+ *
+ *
+ * This file is dual-licensed under both the Magnolia
+ * Network Agreement and the GNU General Public License.
+ * You may elect to use one or the other of these licenses.
+ *
+ * This file is distributed in the hope that it will be
+ * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
+ * Redistribution, except as permitted by whichever of the GPL
+ * or MNA you select, is prohibited.
+ *
+ * 1. For the GPL license (GPL), you can redistribute and/or
+ * modify this file under the terms of the GNU General
+ * Public License, Version 3, as published by the Free Software
+ * Foundation.  You should have received a copy of the GNU
+ * General Public License, Version 3 along with this program;
+ * if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 2. For the Magnolia Network Agreement (MNA), this file
+ * and the accompanying materials are made available under the
+ * terms of the MNA which accompanies this distribution, and
+ * is available at http://www.magnolia-cms.com/mna.html
+ *
+ * Any modifications to this file must keep this entire header
+ * intact.
+ *
+ */
+package info.magnolia.cms.core.search;
+
+import info.magnolia.cms.core.Content;
+import info.magnolia.cms.core.ItemType;
+import info.magnolia.cms.util.QueryUtil;
+import info.magnolia.context.MgnlContext;
+import info.magnolia.importexport.DataTransporter;
+import info.magnolia.test.RepositoryTestCase;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.InvalidQueryException;
+
+
+/**
+ * Imports testdata into the repository during {@link #setUp()} and runs various queries against it
+ * using the Magnolia Query API.
+ * @author jfrantzius
+ *
+ */
+public class QueryTest extends RepositoryTestCase {
+
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream("info/magnolia/cms/core/search/website.level1.xml");
+        DataTransporter.importXmlStream(
+            xmlStream,
+            "website",
+            "/",
+            "name matters only when importing a file that needs XSL transformation",
+            false,
+            ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
+            true,
+            true);
+    }
+
+    /**
+     * Simple query for the single content object with template "home"
+     */
+    public void testSimpleQuery() throws InvalidQueryException, RepositoryException, IOException {
+        String path = "/level1/level2";
+        String templateName = "home";
+
+        String sql = createQueryString(path, templateName);
+
+        QueryManager qm = MgnlContext.getQueryManager("website");
+        Query query = qm.createQuery(sql, Query.SQL);
+        QueryResult magnoliaQueryResult = query.execute();
+        Collection<Content> foundContent = magnoliaQueryResult.getContent();
+        assertFalse(foundContent.isEmpty());
+        assertTrue(foundContent.size() == 1);
+        assertTrue(foundContent.iterator().next().getName().equals("homepage"));
+    }
+
+    public void testMaxResultSize() throws InvalidQueryException, RepositoryException {
+        String path = "/level1/level2";
+        String templateName = "teaserPage1";
+
+        String sql = createQueryString(path, templateName);
+
+        // first query the full result
+        QueryManager qm = MgnlContext.getQueryManager("website");
+        Query query = qm.createQuery(sql, Query.SQL);
+        QueryResult fullQueryResult = query.execute();
+        Collection<Content> fullResult = fullQueryResult.getContent();
+        assertTrue(fullResult.size() == 5);
+        // do same using QueryUtil (
+        fullResult = QueryUtil.query("website", sql, Query.SQL, ItemType.CONTENT.getSystemName());
+        assertTrue(fullResult.size() == 5);
+
+        // now restrict to maxResultSize==3
+        query.setLimit(3);
+        QueryResult restrictedQueryResult = query.execute();
+        Collection<Content> restrictedResult = restrictedQueryResult.getContent();
+        verifyRestrictedResult(fullResult, restrictedResult, 3);
+        // do same using QueryUtil
+        restrictedResult = QueryUtil.query("website", sql, Query.SQL, ItemType.CONTENT.getSystemName(), 3);
+        verifyRestrictedResult(fullResult, restrictedResult, 3);
+    }
+
+    private void verifyRestrictedResult(Collection<Content> full, Collection<Content> restricted, int size) {
+        assertTrue(restricted.size() == size);
+
+        // make sure restricted is a prefix of full
+        Iterator<Content> iterator = full.iterator();
+        for (Content content : restricted) {
+            assertEquals(content.getHandle(), iterator.next().getHandle());
+        }
+    }
+
+    private String createQueryString(String path, String templateName) {
+        String sql = "select * from nt:base where jcr:path like '" + path + "/%' and mgnl:template = '" + templateName
+            + "'";
+        return sql;
+    }
+}
Index: src/test/java/info/magnolia/cms/core/search/website.level1.xml
===================================================================
--- src/test/java/info/magnolia/cms/core/search/website.level1.xml	(revision 0)
+++ src/test/java/info/magnolia/cms/core/search/website.level1.xml	(revision 0)
@@ -0,0 +1,268 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sv:node sv:name="level1" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <sv:property sv:name="jcr:primaryType" sv:type="Name">
+    <sv:value>mgnl:content</sv:value>
+  </sv:property>
+  <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+    <sv:value>mix:lockable</sv:value>
+  </sv:property>
+  <sv:property sv:name="jcr:uuid" sv:type="String">
+    <sv:value>b39ca0a1-052f-42f6-b5eb-13e2e9c6f842</sv:value>
+  </sv:property>
+  <sv:node sv:name="MetaData">
+    <sv:property sv:name="jcr:primaryType" sv:type="Name">
+      <sv:value>mgnl:metaData</sv:value>
+    </sv:property>
+    <sv:property sv:name="mgnl:authorid" sv:type="String">
+      <sv:value>superuser</sv:value>
+    </sv:property>
+    <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+      <sv:value>2010-10-19T15:41:24.281+02:00</sv:value>
+    </sv:property>
+    <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+      <sv:value>2010-10-19T15:42:03.698+02:00</sv:value>
+    </sv:property>
+    <sv:property sv:name="mgnl:template" sv:type="String">
+      <sv:value>folder</sv:value>
+    </sv:property>
+  </sv:node>
+  <sv:node sv:name="level2">
+    <sv:property sv:name="jcr:primaryType" sv:type="Name">
+      <sv:value>mgnl:content</sv:value>
+    </sv:property>
+    <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+      <sv:value>mix:lockable</sv:value>
+    </sv:property>
+    <sv:property sv:name="jcr:uuid" sv:type="String">
+      <sv:value>2b8eee21-84d5-4c49-b0e3-5072f71a18c9</sv:value>
+    </sv:property>
+    <sv:node sv:name="MetaData">
+      <sv:property sv:name="jcr:primaryType" sv:type="Name">
+        <sv:value>mgnl:metaData</sv:value>
+      </sv:property>
+      <sv:property sv:name="mgnl:authorid" sv:type="String">
+        <sv:value>superuser</sv:value>
+      </sv:property>
+      <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+        <sv:value>2010-10-19T15:41:34.941+02:00</sv:value>
+      </sv:property>
+      <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+        <sv:value>2010-10-19T15:42:09.217+02:00</sv:value>
+      </sv:property>
+      <sv:property sv:name="mgnl:template" sv:type="String">
+        <sv:value>folder</sv:value>
+      </sv:property>
+    </sv:node>
+    <sv:node sv:name="homepage">
+      <sv:property sv:name="jcr:primaryType" sv:type="Name">
+        <sv:value>mgnl:content</sv:value>
+      </sv:property>
+      <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+        <sv:value>mix:lockable</sv:value>
+      </sv:property>
+      <sv:property sv:name="jcr:uuid" sv:type="String">
+        <sv:value>da54dab3-999a-4133-b89a-aea3112031c6</sv:value>
+      </sv:property>
+      <sv:node sv:name="MetaData">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:metaData</sv:value>
+        </sv:property>
+        <sv:property sv:name="mgnl:authorid" sv:type="String">
+          <sv:value>superuser</sv:value>
+        </sv:property>
+        <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+          <sv:value>2010-10-19T15:42:12.365+02:00</sv:value>
+        </sv:property>
+        <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+          <sv:value>2010-10-19T15:42:23.693+02:00</sv:value>
+        </sv:property>
+        <sv:property sv:name="mgnl:template" sv:type="String">
+          <sv:value>home</sv:value>
+        </sv:property>
+      </sv:node>
+      <sv:node sv:name="untitled">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>63973bf8-9fa5-4c4f-bee4-5d4767a3eac8</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:06:50.172+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage1</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+      <sv:node sv:name="untitled0">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>0be25d3e-783d-48b1-8e06-786de704bec1</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:activated" sv:type="Boolean">
+            <sv:value>false</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:06:54.851+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage1</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+      <sv:node sv:name="untitled1">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>bdcfe93f-578a-4434-a20d-26b26f75b898</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:activated" sv:type="Boolean">
+            <sv:value>false</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:07:00.088+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage1</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+      <sv:node sv:name="untitled2">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>6a8ce189-2b0f-43e7-aab9-209e107b7bf8</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:activated" sv:type="Boolean">
+            <sv:value>false</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:07:31.707+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage2</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+      <sv:node sv:name="untitled3">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>e681592f-4c69-4cd6-bbf8-8fbf9d1b6118</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:activated" sv:type="Boolean">
+            <sv:value>false</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:07:40.007+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage1</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+      <sv:node sv:name="untitled4">
+        <sv:property sv:name="jcr:primaryType" sv:type="Name">
+          <sv:value>mgnl:content</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+          <sv:value>mix:lockable</sv:value>
+        </sv:property>
+        <sv:property sv:name="jcr:uuid" sv:type="String">
+          <sv:value>48a7b4d1-a596-48d2-95f1-74b24c6e62cb</sv:value>
+        </sv:property>
+        <sv:node sv:name="MetaData">
+          <sv:property sv:name="jcr:primaryType" sv:type="Name">
+            <sv:value>mgnl:metaData</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:activated" sv:type="Boolean">
+            <sv:value>false</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:authorid" sv:type="String">
+            <sv:value>superuser</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:creationdate" sv:type="Date">
+            <sv:value>2010-10-19T19:06:12.803+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
+            <sv:value>2010-10-19T19:07:50.628+02:00</sv:value>
+          </sv:property>
+          <sv:property sv:name="mgnl:template" sv:type="String">
+            <sv:value>teaserPage1</sv:value>
+          </sv:property>
+        </sv:node>
+      </sv:node>
+    </sv:node>
+  </sv:node>
+</sv:node>
Index: src/main/java/info/magnolia/cms/util/QueryUtil.java
===================================================================
--- src/main/java/info/magnolia/cms/util/QueryUtil.java	(revision 38427)
+++ src/main/java/info/magnolia/cms/util/QueryUtil.java	(working copy)
@@ -49,6 +49,7 @@
 import java.util.Collection;
 import java.util.Collections;
 
+
 /**
  * Util to execute queries as simple as possible.
  * @author Philipp Bracher
@@ -56,41 +57,55 @@
  *
  */
 public class QueryUtil {
+
     private static Logger log = LoggerFactory.getLogger(QueryUtil.class);
 
     /**
      * Executes a query.
      */
-    public static Collection<Content> query(String repository, String statement){
-        return query(repository,statement, Query.SQL);
+    public static Collection<Content> query(String repository, String statement) {
+        return query(repository, statement, Query.SQL);
     }
 
     /**
      * Executes a query.
      */
-    public static Collection<Content> query(String repository, String statement, String language){
-        return query(repository,statement,language, ItemType.NT_BASE);
+    public static Collection<Content> query(String repository, String statement, String language) {
+        return query(repository, statement, language, ItemType.NT_BASE);
+    }
+
+    public static Collection<Content> exceptionThrowingQuery(String repository, String statement, String language, String returnItemType) throws RepositoryException {
+        return exceptionThrowingQuery(repository, statement, language, returnItemType, Long.MAX_VALUE);
     }
 
     /**
      * Executes a query, throwing any exceptions that arise as a result.
      */
-    public static Collection<Content> exceptionThrowingQuery(String repository, String statement, String language, String returnItemType) throws RepositoryException {
+    public static Collection<Content> exceptionThrowingQuery(String repository, String statement, String language, String returnItemType,
+        long maxResultSize) throws RepositoryException {
         QueryManager qm = MgnlContext.getQueryManager(repository);
-        Query query= qm.createQuery(statement, language);
+        Query query = qm.createQuery(statement, language);
+        query.setLimit(maxResultSize);
         QueryResult result = query.execute();
         return result.getContent(returnItemType);
     }
 
+    public static Collection<Content> query(String repository, String statement, String language, String returnItemType) {
+        return query(repository, statement, language, returnItemType, Long.MAX_VALUE);
+    }
+
     /**
-     * Executes a query - if an exception is thrown, it is logged and an empty collection is returned.
+     * Executes a query - if an exception is thrown, it is logged and an empty collection is
+     * returned.
      */
-    @SuppressWarnings("unchecked") //Collections.EMPTY_LIST;
-    public static Collection<Content> query(String repository, String statement, String language, String returnItemType) {
+    @SuppressWarnings("unchecked")
+    // Collections.EMPTY_LIST;
+    public static Collection<Content> query(String repository, String statement, String language, String returnItemType, long maxResultSize) {
         try {
-            return exceptionThrowingQuery(repository, statement, language, returnItemType);
-        } catch (Exception e) {
-            log.error("can't execute query [" + statement  + "], will return empty collection", e);
+            return exceptionThrowingQuery(repository, statement, language, returnItemType, maxResultSize);
+        }
+        catch (Exception e) {
+            log.error("can't execute query [" + statement + "], will return empty collection", e);
         }
         return Collections.EMPTY_LIST;
     }
@@ -127,7 +142,7 @@
         calendar.set(Calendar.MILLISECOND, 0);
         StringBuffer str = new StringBuffer("TIMESTAMP '");
         str.append(DateFormatUtils.format(calendar.getTime(), "yyyy-MM-dd'T'HH:mm:ss.SSSZ", calendar.getTimeZone()));
-        str.insert(str.length()-2, ":");
+        str.insert(str.length() - 2, ":");
         str.append("'");
         return str.toString();
     }
Index: src/main/java/info/magnolia/cms/core/search/QueryImpl.java
===================================================================
--- src/main/java/info/magnolia/cms/core/search/QueryImpl.java	(revision 38427)
+++ src/main/java/info/magnolia/cms/core/search/QueryImpl.java	(working copy)
@@ -58,14 +58,20 @@
 
     protected HierarchyManager hm;
 
+    protected long limit = Long.MAX_VALUE;
+
     protected QueryImpl(javax.jcr.query.Query query, HierarchyManager hm) {
         this.query = query;
         this.hm = hm;
     }
 
+    public void setLimit(long limit) {
+        this.limit = limit;
+    }
+
     public QueryResult execute() throws RepositoryException {
         javax.jcr.query.QueryResult result = this.query.execute();
-        QueryResultImpl filteredResult = new QueryResultImpl(result, this.hm);
+        QueryResultImpl filteredResult = new QueryResultImpl(result, this.hm, limit);
         return filteredResult;
     }
 
Index: src/main/java/info/magnolia/cms/core/search/Query.java
===================================================================
--- src/main/java/info/magnolia/cms/core/search/Query.java	(revision 38427)
+++ src/main/java/info/magnolia/cms/core/search/Query.java	(working copy)
@@ -65,6 +65,20 @@
     QueryResult execute() throws RepositoryException;
 
     /**
+     * Restrict the result size of subsequent {@link #execute()} invocations to the given
+     * number of objects.<p>
+     * Use this method if the query result can be large, but you are interested
+     * only in the first few objects. This will avoid the rest of the result objects
+     * to be instantiated, resulting in a huge performance gain for large
+     * results and small limit numbers.<p>
+     * The performance gain may be defeated if your query returns a lot of nodes
+     * of the "wrong" nodetype, resulting in {@link QueryResult#getContent(String)} to
+     * iterate often before the limit is reached. So make sure your query yields only nodes with the
+     * required nodetype.
+     */
+    void setLimit(long limit);
+
+    /**
      * <i>Description inherited from javax.jcr.query.Query#getStatement()</i><br>
      * Returns the statement set for this query.
      * @return the query statement.
Index: src/main/java/info/magnolia/cms/core/search/QueryResultImpl.java
===================================================================
--- src/main/java/info/magnolia/cms/core/search/QueryResultImpl.java	(revision 38427)
+++ src/main/java/info/magnolia/cms/core/search/QueryResultImpl.java	(working copy)
@@ -54,12 +54,12 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
- * Wrapping a JCR {@link javax.jcr.query.QueryResult}. This class will filter
- * the result according to the user's ACLs. You can use
- * {@link #getContent(String)} to retrieve nodes of a certain type. If the
- * node's type doesn't match the nearest matching ancestors is add instead. This
- * allows to search in paragraph content while retrieving  a list of pages.
+ * Wrapping a JCR {@link javax.jcr.query.QueryResult}. This class will filter the result according
+ * to the user's ACLs. You can use {@link #getContent(String)} to retrieve nodes of a certain type.
+ * If the node's type doesn't match the nearest matching ancestors is add instead. This allows to
+ * search in paragraph content while retrieving a list of pages.
  *
  * @author Sameer Charles
  * @author Fabrizio Giustina
@@ -88,12 +88,19 @@
 
     protected HierarchyManager hm;
 
+    protected final long maxResultSize;
+
     protected Map<String, String> dirtyHandles = new Hashtable<String, String>();
 
     protected QueryResultImpl(javax.jcr.query.QueryResult result, HierarchyManager hm) {
+        this(result, hm, Long.MAX_VALUE);
+    }
+
+    protected QueryResultImpl(javax.jcr.query.QueryResult result, HierarchyManager hm, long maxResultSize) {
         this.result = result;
         this.hm = hm;
         this.accessManager = hm.getAccessManager();
+        this.maxResultSize = maxResultSize;
     }
 
     /**
@@ -109,7 +116,8 @@
     }
 
     /**
-     * Adds all found nodes of a certain type. If the type doesn't match it will traverse the ancestors and add them instead.
+     * Adds all found nodes of a certain type. If the type doesn't match it will traverse the
+     * ancestors and add them instead.
      */
     protected void build(String nodeType, Collection<Content> collection) throws RepositoryException {
         this.objectStore.put(nodeType, collection);
@@ -118,7 +126,7 @@
         // whitespace separated list (can't hurt since a single nodetype name can't contain a space)
         String[] nodeTypes = StringUtils.split(nodeType);
 
-        while (nodeIterator.hasNext()) {
+        while (collection.size() < maxResultSize && nodeIterator.hasNext()) {
             Node node = nodeIterator.nextNode();
             try {
                 build(node, nodeTypes, collection);
@@ -141,7 +149,7 @@
         /**
          * All custom node types
          */
-        if ((nodeType== null || nodeType.length == 0) || isNodeType(node, nodeType) && !node.isNodeType(ItemType.NT_RESOURCE)) {
+        if ((nodeType == null || nodeType.length == 0) || isNodeType(node, nodeType) && !node.isNodeType(ItemType.NT_RESOURCE)) {
             if (this.dirtyHandles.get(node.getPath()) == null) {
                 boolean isAllowed = this.hm.getAccessManager().isGranted(Path.getAbsolutePath(node.getPath()), Permission.READ);
                 if (isAllowed) {
