Skip to content

Commit

Permalink
MDL-53226 search_simpledb: Refine the patch
Browse files Browse the repository at this point in the history
- Clumsy fallback only when there is no full-text search support
- Mimic solr tests
- pgsql tokenization using simple configuration
- workaround for mysql '*' search issue
- total results proper calculation
- SQL server FTS support
- Standarize dml full-text search checkings
- Upgrade note about the new dml method
- Set search_simpledb as default engine if no solr config
  • Loading branch information
David Monllao committed Mar 20, 2018
1 parent b602463 commit c2e9707
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 118 deletions.
2 changes: 1 addition & 1 deletion admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
// Search engine selection.
$temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
$temp->add(new admin_setting_configselect('searchengine',
new lang_string('selectsearchengine', 'admin'), '', 'solr', $engines));
new lang_string('selectsearchengine', 'admin'), '', 'simpledb', $engines));
$temp->add(new admin_setting_heading('searchoptionsheading', new lang_string('searchoptions', 'admin'), ''));
$temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
Expand Down
9 changes: 9 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2020,5 +2020,14 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2018022800.03);
}

if ($oldversion < 2018031600.01) {

// Update default search engine to search_simpledb if global search is disabled and there is no solr index defined.
if (empty($CFG->enableglobalsearch) && empty(get_config('search_solr', 'indexname'))) {
set_config('searchengine', 'simpledb');
}
upgrade_main_savepoint(true, 2018031600.01);
}

return true;
}
14 changes: 14 additions & 0 deletions lib/dml/mariadb_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@ protected function transactions_supported() {
}
return true;
}

/**
* Does this mariadb instance support fulltext indexes?
*
* @return bool
*/
public function is_fulltext_search_supported() {
$info = $this->get_server_info();

if (version_compare($info['version'], '10.0.5', '>=')) {
return true;
}
return false;
}
}
10 changes: 10 additions & 0 deletions lib/dml/moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2687,4 +2687,14 @@ public function perf_get_queries() {
public function perf_get_queries_time() {
return $this->queriestime;
}

/**
* Whether the database is able to support full-text search or not.
*
* @return bool
*/
public function is_fulltext_search_supported() {
// No support unless specified.
return false;
}
}
14 changes: 14 additions & 0 deletions lib/dml/mysqli_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1989,4 +1989,18 @@ public function convert_table_row_format($tablename) {
$this->change_database_structure("ALTER TABLE {$prefix}$tablename $rowformat");
}
}

/**
* Does this mysql instance support fulltext indexes?
*
* @return bool
*/
public function is_fulltext_search_supported() {
$info = $this->get_server_info();

if (version_compare($info['version'], '5.6.4', '>=')) {
return true;
}
return false;
}
}
9 changes: 9 additions & 0 deletions lib/dml/pgsql_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,4 +1497,13 @@ protected function rollback_transaction() {
private function trim_quotes($str) {
return trim(trim($str), "'\"");
}

/**
* Postgresql supports full-text search indexes.
*
* @return bool
*/
public function is_fulltext_search_supported() {
return true;
}
}
22 changes: 22 additions & 0 deletions lib/dml/sqlsrv_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1586,4 +1586,26 @@ protected function rollback_transaction() {
$result = sqlsrv_rollback($this->sqlsrv);
$this->query_end($result);
}

/**
* Is fulltext search enabled?.
*
* @return bool
*/
public function is_fulltext_search_supported() {
global $CFG;

$sql = "SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = sqlsrv_query($this->sqlsrv, $sql);
$this->query_end($result);
if ($result) {
if ($row = sqlsrv_fetch_array($result)) {
$property = (bool)reset($row);
}
}
$this->free_result($result);

return !empty($property);
}
}
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ information provided here is intended especially for developers.
* Scripts can define a constant NO_SITEPOLICY_CHECK and set it to true before requiring the main config.php file. It
will make the require_login() skipping the test for the user's policyagreed status. This is useful for plugins that
act as a site policy handler.
* There is a new is_fulltext_search_supported() DML function. The default implementation returns false. This function
is used by 'Simple search' global search engine to determine if the database full-text search capabilities can be used.

=== 3.4 ===

Expand Down
6 changes: 2 additions & 4 deletions search/classes/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ public static function format_time_for_engine($timestamp) {
* @return string
*/
public static function format_string_for_engine($string) {
//FIXME: this shouldn't be required. Where is bad utf8 coming from?
return fix_utf8($string);
return $string;
}

/**
Expand All @@ -421,8 +420,7 @@ public static function format_string_for_engine($string) {
* @return string
*/
public static function format_text_for_engine($text) {
//FIXME: this shouldn't be required. Where is bad utf8 coming from?
return fix_utf8($text);
return $text;
}

/**
Expand Down
Loading

0 comments on commit c2e9707

Please sign in to comment.