I am attempting to write a stored procedure that can take in k words and return back the answers with the k words in them.
word table
- word
- wordId
description word inverted index
- descriptionID
- wordID
- count
So – given k words, how would I efficiently get all the descriptionIDs that contain the ALL the k words?
The easiest way in a single query is to use a combination of the
INandHAVINGclauses. Example:The number of values in the
INclause must match the number of distinct values counted in theHAVINGclause.Another means is to JOIN to multiple copies of the WORD table (in this case) for each specific word: