mysql 倒序 索引,MySQL查询倒排索引数据

I have thousand of pages in website which I parsed and stored it as Inverted Index viz

document

docid (PK,FK)

url

charactercount

wordcount

Charactercount and wordcount helps me determine long document from short which I may use later.

word

wordid (PK,FK)

word

doc_freq

inverse_doc_freq

For inverse_doc_freq calculation I use fictional high number (100000000) to prevent total document recalculation.

loc

wordid

docid

word_freq

weight

(wordid & docid combined unique)

The weight is a score calculated on simple basis like word in title + word in url + word frquency etc.

I am having problem framing my sql query for search words. For 3 word search I am doing like

Break query into each word

Check inverse_doc_freq for each word and remove low idf word (removal of stop word)

stem the remaining word (assume still 3 words remain)

Query for each word

It is at stage 4 that I am getting stuck ! My SQL query is like

SELECT d.docid,url,inverse_doc_freq,word_freq,weight from document d,word w,loc l WHERE d.docid=l.docid AND w.wordid=l.wordid AND (word='word1' OR word='word2' OR word='word3') ORDER BY weight DESC

The returned documents are not correct though. Trust I might have to Search thrice to find documents for each word and then try to find the common documents, but how ? Is it possible to use only 1 MySQL query for it ? Also is it possible to use TF-IDF and how ?

解决方案

You need to aggregate at the document level.

select d.docid, d.url, sum(weight) as weight

from document d join

loc l

on d.docid = l.docid join

word w

on w.wordid = l.wordid

where w.word in ('word1', 'word2', 'word3')

group by d.docid

order by weight DESC;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值