comparison forum/Sources/DbSearch-postgresql.php @ 76:e3e11437ecea website

Add forum code
author Chris Cannam
date Sun, 07 Jul 2013 11:25:48 +0200
parents
children
comparison
equal deleted inserted replaced
75:72f59aa7e503 76:e3e11437ecea
1 <?php
2
3 /**
4 * Simple Machines Forum (SMF)
5 *
6 * @package SMF
7 * @author Simple Machines http://www.simplemachines.org
8 * @copyright 2011 Simple Machines
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
10 *
11 * @version 2.0
12 */
13
14 if (!defined('SMF'))
15 die('Hacking attempt...');
16
17 /* This file contains database functions specific to search related activity.
18
19 void db_search_init()
20 - adds the functions in this file to the $smcFunc array
21
22 boolean smf_db_search_support($search_type)
23 - whether this database type support the search type $search_type
24
25 void smf_db_create_word_search($size)
26 - create the custom word index table
27
28 resource smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null)
29 - returns the correct query for this search type.
30 */
31
32 // Add the file functions to the $smcFunc array.
33 function db_search_init()
34 {
35 global $smcFunc;
36
37 if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query')
38 $smcFunc += array(
39 'db_search_query' => 'smf_db_search_query',
40 'db_search_support' => 'smf_db_search_support',
41 'db_create_word_search' => 'smf_db_create_word_search',
42 'db_support_ignore' => false,
43 );
44 }
45
46 // Does this database type support this search type?
47 function smf_db_search_support($search_type)
48 {
49 $supported_types = array('custom');
50
51 return in_array($search_type, $supported_types);
52 }
53
54 // Returns the correct query for this search type.
55 function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null)
56 {
57 global $smcFunc;
58
59 $replacements = array(
60 'create_tmp_log_search_topics' => array(
61 '~mediumint\(\d\)~i' => 'int',
62 '~unsigned~i' => '',
63 '~TYPE=HEAP~i' => '',
64 ),
65 'create_tmp_log_search_messages' => array(
66 '~mediumint\(\d\)' => 'int',
67 '~unsigned~i' => '',
68 '~TYPE=HEAP~i' => '',
69 ),
70 'drop_tmp_log_search_topics' => array(
71 '~IF\sEXISTS~i' => '',
72 ),
73 'drop_tmp_log_search_messages' => array(
74 '~IF\sEXISTS~i' => '',
75 ),
76 'insert_into_log_messages_fulltext' => array(
77 '~NOT\sRLIKE~i' => '!~*',
78 '~RLIKE~i' => '~*',
79 ),
80 'insert_log_search_results_subject' => array(
81 '~NOT\sRLIKE~i' => '!~*',
82 '~RLIKE~i' => '~*',
83 ),
84 );
85
86 if (isset($replacements[$identifier]))
87 $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
88 elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
89 {
90 $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
91 // Don't error on multi-insert.
92 $db_values['db_error_skip'] = true;
93 }
94
95 $return = $smcFunc['db_query']('', $db_string,
96 $db_values, $connection
97 );
98
99 return $return;
100 }
101
102 // Highly specific - create the custom word index table!
103 function smf_db_create_word_search($size)
104 {
105 global $smcFunc;
106
107 $size = 'int';
108
109 $smcFunc['db_query']('', '
110 CREATE TABLE {db_prefix}log_search_words (
111 id_word {raw:size} NOT NULL default {string:string_zero},
112 id_msg int NOT NULL default {string:string_zero},
113 PRIMARY KEY (id_word, id_msg)
114 )',
115 array(
116 'size' => $size,
117 'string_zero' => '0',
118 )
119 );
120 }
121
122 ?>