title: Querying Raven with Where() only filters against the first 128 documents?
body: <p>We're using Raven to validate logins so people can get into our site. </p>
  
  <p>What we've found is that if you do this: </p>
  
  <pre><code>// Context is an IDocumentSession 
  Context.Query&lt;UserModels&gt;()
             .SingleOrDefault(u =&gt; u.Email.ToLower() == email.ToLower()); 
  </code></pre>
  
  <p>The query only filters on the first 128 docs of the documents in 
  Raven. There are several thousand in our database, so unless your 
  email happens to be in that first 128 returned, you're out of luck. </p>
  
  <p>None of the Raven samples code or any 
  sample code I've come across on the net performs any looping using 
  Skip() and Take() to iterate through the set. </p>
  
  <ol>
  <li>Is this the desired behavior of Raven? </li>
  <li>Is it the same behavior even if you use an advanced Lucene Query? ie; Do advanced queries behave any differently?</li>
  <li>Is the solution below appropriate? Looks a little ugly. :P</li>
  </ol>
  
  <p>My solution is to loop through the set of all documents until I 
  encounter a non null result, then I break and return . </p>
  
  <pre><code>public T SingleWithIndex(string indexName, Func&lt;T, bool&gt; where)
  {
      var pageIndex = 1;
      const int pageSize = 1024;
      RavenQueryStatistics stats;
  
  var queryResults = Context.Query&lt;T&gt;(indexName)
      .Statistics(out stats)
      .Customize(x =&gt; x.WaitForNonStaleResults())
      .Take(pageSize)
      .Where(where).SingleOrDefault();
  
  if (queryResults == null &amp;&amp; stats.TotalResults &gt; pageSize)
  {
      for (var i = 0; i &lt; (stats.TotalResults / (pageIndex * pageSize)); i++)
      {
          queryResults = Context.Query&lt;T&gt;(indexName)
              .Statistics(out stats)
              .Customize(x =&gt; x.WaitForNonStaleResults())
              .Skip(pageIndex * pageSize)
              .Take(pageSize)
              .Where(where).SingleOrDefault();
  
          if (queryResults != null) break;
  
          pageIndex++;
      }
  
  }
  
  return queryResults;
  </code></pre>
  
  <p>}</p>
  
  <p>EDIT:</p>
  
  <p>Using the fix below is not passing query params to my RavenDB instance. Not sure why yet.</p>
  
  <pre><code>Context.Query&lt;UserModels&gt;()
      .Where(u =&gt; u.Email == email)
      .SingleOrDefault();
  </code></pre>
  
  <p>In the end I am using Advanced Lucene Syntax instead of linq queries and things are working as expected.</p>