Say we have two tables in PostgreSQL:
wordswithtextfield containing the word (English word for now), andid.ngramscontainingtextfield and mapping toword_id.
How would you "select all words which contain x and y"?
select * from words
inner join ngrams on ngrams.word_id = words.id
where ngrams.text = x
and ngrams.text = y
The general problem is, how do I do an AND but use two different records from the ngrams table? What I did just there is compare the same ngram text value to two different variables, asking for AND. That doesn't make sense, it should somehow use two different ngram records. How generally do you do that in PostgreSQL?
Note, I don't want to use PostgreSQL full-text search functionality. I am trying to understand how to implement it at a lower level (manually), and also want to apply to hundreds of languages beyond just English (like to Chinese, which has at least 80k characters).
https://medium.com/@evanwhalen/anatomy-of-an-n-gram-search-b30c6f20ad39