我有三张表,如下所示:
我成功使用了intersect,但是它并没有返回总数和顺序。
documents (id, content)
words (id, word)
word_document (word_id, document_id, count)
Words table(单词表)包含了所有文件中出现过的单词,word_document(单词文档)将一个单词与一个文档相关联,并记录该单词在该文档中的出现次数。
我想编写一个查询来搜索两个单词,并仅返回同时拥有这两个单词的文档,按照这两个单词在文档中的计数之和排序。
例如
DocA: green apple is not blue
DocB: blue apple is blue
DocC: red apple is red
现在搜索苹果和蓝色将返回以下结果:
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,但是它并没有返回总数和顺序。