-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_test_cmd.php
More file actions
50 lines (37 loc) · 1.4 KB
/
parse_test_cmd.php
File metadata and controls
50 lines (37 loc) · 1.4 KB
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
Full Text Search Parser - Version 2.0 - Test
Operators: AND & OR | NOT ! and escaped characters with \
Exact phrases can be ensured by using double or single quotes "like this" or 'exact phrase'
Nested operator order is supported using ( and )
Spaces between keywords can default to AND, OR, or none
Only considering uppercase AND, OR, and NOT as operators can be selected
Supports generating prepared statments or traditional SQL
Test Search Phrase: <?php
$text = trim(fgets(STDIN));
require_once 'parse_model.php';
$o_parse = new parse_model();
$o_parse->debug = true;
$o_parse->use_prepared_sql = false;
// Required for the PDO::quote() function.
//$o_db = new PDO('pgsql:host=localhost;dbname=mydb', 'user', 'pass');
if ( $text != '' )
{
if ( $o_parse->parse($text, 'fulltext') == false )
echo "Message to user: [$o_parse->error_msg]\n\n";
else
{
$query = "SELECT * FROM some_table WHERE ";
if ( $o_parse->tsearch != '' )
$query .= "fulltext @@ to_tsquery('$o_parse->tsearch') ";
//$query .= "fulltext @@ to_tsquery(" . $o_db->quote($o_parse->tsearch) . ")\n";
if ( $o_parse->ilike != '' )
$query .= ($o_parse->tsearch != '' ? "AND " : '') . "($o_parse->ilike)";
echo "\nSample Query: $query\n\n";
/*
$o_q = $o_db->prepare($query);
foreach ( $o_parse->db_ilike_data as $varname => $value )
$o_q->bindValue($varname, $value);
$o_q->execute();
*/
}
}
?>