DOCTYPE html -- To change this license header choose License Headers i

 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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="index.php" method="POST">
<textarea name=textarea placeholder="Введите фразу для поиска по названию"></textarea>
<input type="submit" name="input">
</form>
<?php
require "vendor\autoload.php";
use Zend\Db\Sql\Sql;
use Zend\Db\Adapter\Adapter;
$adapter = new Adapter(array(
'driver' => 'Pdo_Pgsql',
'database' => 'newdatabase',
'username' => 'Pavel',
'password' => '115663225'
));
$sql = new Sql($adapter);
print('<br>');
if (isset($_POST['textarea'])){
$findString = $_POST['textarea'];
/*$time1 = microtime(true);
$selectWithFind = $sql->select();
$selectWithFind -> columns(array('movie_id', 'title'));
$selectWithFind -> where ('title LIKE ?');
$selectWithFind -> where ('description LIKE ?', \Zend\Db\Sql\Predicate\PredicateSet::COMBINED_BY_OR);
$selectWithFind -> from('MovieTable');
$selectWithFind -> limit(10);
$statement = $sql->prepareStatementForSqlObject($selectWithFind);
$result = $statement -> execute(array('%'.$findString.'%', '%'.$findString.'%'));
print (microtime(true)-$time1);
print('<br>');
foreach($result as $row){
print_r($row);
print('<br>');
}
print('<br>');*/
$stringsNC = explode(',', $findString);
for ($q = 0; $q <count($stringsNC); $q++){
$curString = trim($stringsNC[$q]);
$stringsWithSpaceNC = explode(' ', $curString);
$stringWithSpaceWC = "(".implode('&', $stringsWithSpaceNC).")";
$stringsWithSpaceWC[] = $stringWithSpaceWC;
}
$resultString = implode('|', $stringsWithSpaceWC);
var_dump($resultString);
$time1 = microtime(true);
$selectWithLexems = $sql->select();
$selectWithLexems -> columns(array('movie_id', 'title'));
$selectWithLexems -> where('to_tsvector(\'russian\', description) @@ to_tsquery(\'russian\', ?)');
$selectWithLexems -> where('to_tsvector(\'russian\', title) @@ to_tsquery(\'russian\', ?)', \Zend\Db\Sql\Predicate\PredicateSet::COMBINED_BY_OR);
$selectWithLexems -> from('MovieTable');
$selectWithLexems -> limit(10);
$statement1 = $sql->prepareStatementForSqlObject($selectWithLexems);
$result = $statement1 -> execute(array($resultString, $resultString));
print (microtime(true)-$time1);
print ('<br>');
foreach($result as $row){
print_r($row);
print('<br>');
}
}
?>
</body>
</html>