-
Notifications
You must be signed in to change notification settings - Fork 1
/
searchwavelet.php
85 lines (78 loc) · 2.06 KB
/
searchwavelet.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
include 'db.php';
include 'queries.php';
include 'classes.php';
if(isset($_POST['keyword'])) {
$keyword = $_POST['keyword'];
$keys = explode(' ', $keyword);
/* create dictionary starts*/
$t_create_start = microtime(true);
$qobj = new Queries();
$wtree = new WaveletTree();
$wtreeop = new WaveletOperation();
$content = array();
$contentlist = array();
$docidlist = array();
$doclist = $qobj->retrieve_documents($conn);
while($row = $doclist->fetch()) {
echo $row['doc_id']." => ";
echo $row['content'];
$content = explode(' ', $row['content']);
array_push($docidlist, $row['doc_id']);
array_push($contentlist, $content);
echo "<br>";
}
$collection = array_combine($docidlist, $contentlist);
$dictionary = array();
// create dictionary list
foreach($collection as $doc=>$content) {
foreach($content as $i=>$word) {
$word = strtolower($word);
array_push($dictionary, array($word, $doc));
}
}
/* create dictionary ends*/
/*wavelet creation starts*/
$A = array();
$B = array();
$n = count($dictionary);
$docn = count($docidlist);
for($i = 0; $i<$n; $i++) {
$val = $dictionary[$i][1];
$A[$i] = $val;
if($val <=$docn/2)
$B[$i] = 0;
else $B[$i] = 1;
}
$wtree->insert($A, $B);
$t_create_end = microtime(true);
/*wavelet creation ends*/
/*searching starts*/
$t_search_start = microtime(true);
$x = array();
echo "<br>We have";
foreach($keys as $keyword) {
echo ", $keyword";
$keyword = strtolower($keyword);
foreach($dictionary as $k=>$kd) {
if($keyword == $kd[0]) {
$temp = $wtree->currentNode();
$tpos = $k;
array_push($x, $wtreeop->display($temp, $tpos));
}
}
}
$x = array_unique($x);
asort($x);
var_dump($x);
$t_search_end = microtime(true);
/*searching ends*/
echo "For indexing=> ".($ct = $t_create_end - $t_create_start)."<br>";
echo "For searching=> ".($st = $t_search_end - $t_search_start)."<br>";
echo "For total=> ".($st + $ct);
}
?>
<form action="searchwavelet.php" method="POST">
Enter keyword to search:<input type="text" name="keyword"><br>
<input type="submit" value="Find">
</form>