title: Lucene nested queries
body: <p>I have this situation</p>
  
  <pre><code>Entity Company_id 
  -----------------
  E001     1        
  E001     2       
  E003     1
  E002     2
  E001     3
  E003     3
  </code></pre>
  
  <p>I want to know how much companies that have entities (E001 and E003) in this case the result should be company 1 and 3.</p>
  
  <p>In SQL it can be resolved by making a nested query but I should use something like luncene because of performance needs this query will be executed more that 50 times for each page.</p>
  
  <p>Note : I can have to restrict on 3 or 4 entities also ex : all companies that have (E001 AND E002 AND E003 AND 3004).</p>
  
  <p>Any help will be appreciated</p>
  
  <p><strong>EDIT</strong>
  I know that lucene is made for text search but let's suppose that each row is a Document in the index.</p>