我有三个表如下:
documents (id, content)
words (id, word)
word_document (word_id, document_id, count)
单词表包含所有文档中出现的所有单词,word_document 将单词与文档以及该文档中该单词的计数相关联。
我想编写一个查询来搜索两个单词,并只返回两个单词都按文档中两个单词的计数总和排序的文档。
例如
DocA: green apple is not blue
DocB: blue apple is blue
DocC: red apple is red
现在搜索apple和blue返回:
DocA, 3
DocB, 2
因为:
DocA contains both words and 3 of them
DocB contains both words and 2 of them
DocC only contains one word
我成功使用了intersect但它不返回计数和也没有顺序。