Commit 909d6928 authored by Steven Wittens's avatar Steven Wittens

- #28159: Advanced search features (hello from DrupalCon)

Presentation about it:
http://www.acko.net/files/drupal-search-slim.pdf
parent 782d5c98
......@@ -562,6 +562,16 @@ CREATE TABLE role (
UNIQUE KEY name (name)
) TYPE=MyISAM;
--
-- Table structure for table 'search_dataset'
--
CREATE TABLE search_dataset (
sid int(10) unsigned NOT NULL default '0',
type varchar(16) default NULL,
data longtext NOT NULL,
KEY sid_type (sid, type)
) TYPE=MyISAM;
--
-- Table structure for table 'search_index'
--
......@@ -572,9 +582,9 @@ CREATE TABLE search_index (
type varchar(16) default NULL,
fromsid int(10) unsigned NOT NULL default '0',
fromtype varchar(16) default NULL,
score int(10) unsigned default NULL,
KEY sid (sid),
KEY fromsid (fromsid),
score float default NULL,
KEY sid_type (sid, type),
KEY from_sid_type (fromsid, fromtype),
KEY word (word)
) TYPE=MyISAM;
......@@ -584,7 +594,7 @@ CREATE TABLE search_index (
CREATE TABLE search_total (
word varchar(50) NOT NULL default '',
count int(10) unsigned default NULL,
count float default NULL,
PRIMARY KEY (word)
) TYPE=MyISAM;
......
......@@ -571,6 +571,16 @@ CREATE TABLE role (
UNIQUE (name)
);
--
-- Table structure for table 'search_dataset'
--
CREATE TABLE search_dataset (
sid integer NOT NULL default '0',
type varchar(16) default NULL,
data text NOT NULL default '',
KEY sid_type (sid, type)
);
--
-- Table structure for search_index
--
......@@ -581,10 +591,10 @@ CREATE TABLE search_index (
type varchar(16) default NULL,
fromsid integer NOT NULL default '0',
fromtype varchar(16) default NULL,
score integer default NULL
score float default NULL
);
CREATE INDEX search_index_sid_idx ON search_index(sid);
CREATE INDEX search_index_fromsid_idx ON search_index(fromsid);
CREATE INDEX search_index_sid_type_idx ON search_index(sid, type);
CREATE INDEX search_index_from_sid_type_idx ON search_index(fromsid, fromtype);
CREATE INDEX search_index_word_idx ON search_index(word);
--
......
......@@ -66,7 +66,8 @@
"2005-08-25" => "update_146",
"2005-09-07" => "update_147",
"2005-09-18" => "update_148",
"2005-09-27" => "update_149"
"2005-09-27" => "update_149",
"2005-10-15" => "update_150"
);
function update_110() {
......@@ -846,6 +847,78 @@ function update_149() {
return $ret;
}
function update_150() {
$ret = array();
$ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
$ret[] = update_sql("DELETE FROM {variable} WHERE name = 'minimum_word_size'");
$ret[] = update_sql("DELETE FROM {variable} WHERE name = 'remove_short'");
$ret[] = update_sql("DELETE FROM {node_counter} WHERE nid = 0");
$ret[] = update_sql('DROP TABLE {search_index}');
$ret[] = update_sql('DROP TABLE {search_total}');
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("CREATE TABLE {search_dataset} (
sid int(10) unsigned NOT NULL default '0',
type varchar(16) default NULL,
data longtext NOT NULL,
KEY sid_type (sid, type)
)");
$ret[] = update_sql("CREATE TABLE {search_index} (
word varchar(50) NOT NULL default '',
sid int(10) unsigned NOT NULL default '0',
type varchar(16) default NULL,
fromsid int(10) unsigned NOT NULL default '0',
fromtype varchar(16) default NULL,
score float default NULL,
KEY sid_type (sid, type),
KEY from_sid_type (fromsid, fromtype),
KEY word (word)
)");
$ret[] = update_sql("CREATE TABLE {search_total} (
word varchar(50) NOT NULL default '',
count float default NULL,
PRIMARY KEY word (word)
)");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {search_dataset} (
sid integer NOT NULL default '0',
type varchar(16) default NULL,
data text NOT NULL default '',
KEY sid_type (sid, type)
)");
$ret[] = update_sql("CREATE TABLE {search_index} (
word varchar(50) NOT NULL default '',
sid integer NOT NULL default '0',
type varchar(16) default NULL,
fromsid integer NOT NULL default '0',
fromtype varchar(16) default NULL,
score float default NULL
)");
$ret[] = update_sql("CREATE INDEX search_index_sid_type_idx ON {search_index}(sid, type)");
$ret[] = update_sql("CREATE INDEX search_index_from_sid_type_idx ON {search_index}(fromsid, fromtype)");
$ret[] = update_sql("CREATE INDEX search_index_word_idx ON {search_index}(word)");
$ret[] = update_sql("CREATE TABLE {search_total} (
word varchar(50) NOT NULL default '',
count float default NULL
)");
$ret[] = update_sql("CREATE INDEX search_total_word_idx ON {search_total}(word)");
break;
default:
break;
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -238,6 +238,50 @@ function db_query_range($query) {
return _db_query($query);
}
/**
* Runs a SELECT query and stores its results in a temporary table.
*
* Use this as a substitute for db_query() when the results need to stored
* in a temporary table. Temporary tables exist for the duration of the page
* request.
* User-supplied arguments to the query should be passed in as separate parameters
* so that they can be properly escaped to avoid SQL injection attacks.
*
* Note that if you need to know how many results were returned, you should do
* a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and
* db_affected_rows() do not give consistent result across different database
* types in this case.
*
* @param $query
* A string containing a normal SELECT SQL query.
* @param ...
* A variable number of arguments which are substituted into the query using
* printf() syntax. Instead of a variable number of query arguments, you may
* also pass a single array containing the query arguments.
* @param $table
* The name of the temporary table to select into. This name will not be
* prefixed as there is no risk of collision.
* @return
* A database query result resource, or FALSE if the query was not executed
* correctly.
*/
function db_query_temporary($query) {
$args = func_get_args();
$tablename = array_pop($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', db_prefix_tables($query));
if (count($args) > 1) {
// Check for array (alternative syntax).
if (is_array($args[1])) {
$args = array_merge(array($query), $args[1]);
}
$args = array_map('db_escape_string', $args);
$args[0] = $query;
$query = call_user_func_array('sprintf', $args);
}
return _db_query($query);
}
/**
* Returns a properly formatted Binary Large OBject value.
*
......
......@@ -205,6 +205,11 @@ function db_affected_rows() {
* User-supplied arguments to the query should be passed in as separate parameters
* so that they can be properly escaped to avoid SQL injection attacks.
*
* Note that if you need to know how many results were returned, you should do
* a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and
* db_affected_rows() do not give consistent result across different database
* types in this case.
*
* @param $query
* A string containing an SQL query.
* @param ...
......@@ -238,6 +243,50 @@ function db_query_range($query) {
return _db_query($query);
}
/**
* Runs a SELECT query and stores its results in a temporary table.
*
* Use this as a substitute for db_query() when the results need to stored
* in a temporary table. Temporary tables exist for the duration of the page
* request.
* User-supplied arguments to the query should be passed in as separate parameters
* so that they can be properly escaped to avoid SQL injection attacks.
*
* Note that if you need to know how many results were returned, you should do
* a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and
* db_affected_rows() do not give consistent result across different database
* types.
*
* @param $query
* A string containing a normal SELECT SQL query.
* @param ...
* A variable number of arguments which are substituted into the query using
* printf() syntax. Instead of a variable number of query arguments, you may
* also pass a single array containing the query arguments.
* @param $table
* The name of the temporary table to select into. This name will not be
* prefixed as there is no risk of collision.
* @return
* A database query result resource, or FALSE if the query was not executed
* correctly.
*/
function db_query_temporary($query) {
$args = func_get_args();
$tablename = array_pop($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', db_prefix_tables($query));
if (count($args) > 1) {
// Check for array (alternative syntax).
if (is_array($args[1])) {
$args = array_merge(array($query), $args[1]);
}
$args = array_map('db_escape_string', $args);
$args[0] = $query;
$query = call_user_func_array('sprintf', $args);
}
return _db_query($query);
}
/**
* Returns a properly formatted Binary Large OBject value.
*
......
......@@ -223,6 +223,50 @@ function db_query_range($query) {
return _db_query($query);
}
/**
* Runs a SELECT query and stores its results in a temporary table.
*
* Use this as a substitute for db_query() when the results need to stored
* in a temporary table. Temporary tables exist for the duration of the page
* request.
* User-supplied arguments to the query should be passed in as separate parameters
* so that they can be properly escaped to avoid SQL injection attacks.
*
* Note that if you need to know how many results were returned, you should do
* a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and
* db_affected_rows() do not give consistent result across different database
* types in this case.
*
* @param $query
* A string containing a normal SELECT SQL query.
* @param ...
* A variable number of arguments which are substituted into the query using
* printf() syntax. Instead of a variable number of query arguments, you may
* also pass a single array containing the query arguments.
* @param $table
* The name of the temporary table to select into. This name will not be
* prefixed as there is no risk of collision.
* @return
* A database query result resource, or FALSE if the query was not executed
* correctly.
*/
function db_query_temporary($query) {
$args = func_get_args();
$tablename = array_pop($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' AS', db_prefix_tables($query));
if (count($args) > 1) {
// Check for array (alternative syntax).
if (is_array($args[1])) {
$args = array_merge(array($query), $args[1]);
}
$args = array_map('db_escape_string', $args);
$args[0] = $query;
$query = call_user_func_array('sprintf', $args);
}
return _db_query($query);
}
/**
* Returns a properly formatted Binary Large OBject value.
*
......
......@@ -445,6 +445,13 @@ img.screenshot {
.search-results .search-info {
font-size: 0.85em;
}
.search-advanced .criterium {
float: left;
margin-right: 2em;
}
.search-advanced .action {
clear: left;
}
#tracker td.replies {
text-align: center;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment