forked from rajat19/Wavelet-and-Btree-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.php
62 lines (48 loc) · 1.64 KB
/
queries.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class Queries {
public function retrieve_documents($conn) {
$sql = "SELECT * FROM pages";
$run = $conn->prepare($sql);
$run->execute();
return $run;
}
public function word_exist($conn, $word) {
$sql = "SELECT frequency FROM dictionary WHERE word=:word";
$run = $conn->prepare($sql);
$run->bindParam(':word', $word);
$run->execute();
if($run->rowCount() > 0)
return true;
return false;
}
public function dict_insert($conn, $word) {
$sql = "INSERT INTO dictionary(frequency, word) VALUES (:frequency, :word) ON DUPLICATE KEY UPDATE frequency=VALUES(frequency + 1), word=VALUES(word)";
$run = $conn->prepare($sql);
$frequency = 1;
$run->bindParam(':word', $word);
$run->bindParam(':frequency', $frequency);
$run->execute();
}
public function doc_insert($conn, $docid, $word) {
$sql = "INSERT INTO documents(doc_id, word) VALUES (:docid, :word) ON DUPLICATE KEY UPDATE doc_id=VALUES(doc_id), word=VALUES(word)";
$run = $conn->prepare($sql);
$run->bindParam(':word', $word);
$run->bindParam(':docid', $docid);
$run->execute();
}
public function inv_insert($conn, $word, $docid, $pos) {
$sql = "INSERT INTO inverted_index(word, doc_id, position) VALUES (:word, :docid, :pos) ON DUPLICATE KEY UPDATE doc_id=VALUES(doc_id), word=VALUES(word), position=VALUES(position) ";
$run = $conn->prepare($sql);
$run->bindParam(':word', $word);
$run->bindParam(':docid', $docid);
$run->bindParam(':pos', $pos);
$run->execute();
}
public function get_total_doc($conn) {
$sql = "SELECT COUNT(DISTINCT doc_id) FROM inverted_index";
$run = $conn->prepare($sql);
$run->execute();
return $run;
}
}
?>