How do search engines such as Lucene, etc. perform AND queries where a term is common to many documents in the dataset? For example, in an inverted index of:
term | document_id
---------------------
program | 1, 2, 3, 5...
python | 1, 4
code | 4
c++ | 4, 5
the term program
is present in several documents meaning a query of program AND code
would require performing an intersection upon a very large set of documents.
Is there a way to perform AND queries without having to take the intersection of terms contained by potentially billions of documents?