-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassignment2_i.sql
More file actions
22 lines (21 loc) · 816 Bytes
/
Copy pathassignment2_i.sql
File metadata and controls
22 lines (21 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
------------------------------------------------------------
-- Find the best matching document to the keyword query
-- "washington taxes treasury".
------------------------------------------------------------
-- create a new table q
create table if not exists q ( kw varchar(20) );
insert into q values('washington');
insert into q values('taxes');
insert into q values('treasury');
select max(v) as similarity from (
SELECT A.docid, B.docid as b, SUM(A.count) as v
FROM frequency as A join frequency as B on A.term = B.term
WHERE
A.docid < B.docid
and a.term in (select kw from q) -- ('washington','taxes','treasury')
and b.term in (select kw from q) -- ('washington','taxes','treasury')
-- Since we're limiting ourselves to a specific set of documents,
-- our query is faster
GROUP BY A.docid, B.docid
)
;