/**
  * When enabled, the FTS index is created, so queries that rely on FTS work.
  */
 public function testEnabled()
 {
     if (!$this->supportsFts()) {
         $this->markTestSkipped("Local installation of InnoDB does not support FTS.");
         return;
     }
     $idx = new CRM_Core_InnoDBIndexer(TRUE, array('civicrm_contact' => array(array('first_name', 'last_name'))));
     $idx->fixSchemaDifferences();
     CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
 }
 /**
  * Create a SQL expression for matching against a list of
  * text columns.
  *
  * @param string $table eg "civicrm_note" or "civicrm_note mynote"
  * @param array|string $fullTextFields list of field names
  * @param string $queryText
  * @return string SQL, eg "MATCH (col1) AGAINST (queryText)" or "col1 LIKE '%queryText%'"
  */
 public function matchText($table, $fullTextFields, $queryText)
 {
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     if (strpos($table, ' ') === FALSE) {
         $tableName = $tableAlias = $table;
     } else {
         list($tableName, $tableAlias) = explode(' ', $table);
     }
     if (is_scalar($fullTextFields)) {
         $fullTextFields = array($fullTextFields);
     }
     $clauses = array();
     if (CRM_Core_InnoDBIndexer::singleton()->hasDeclaredIndex($tableName, $fullTextFields)) {
         $formattedQuery = CRM_Utils_QueryFormatter::singleton()->format($queryText, CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL);
         $prefixedFieldNames = array();
         foreach ($fullTextFields as $fieldName) {
             $prefixedFieldNames[] = "{$tableAlias}.{$fieldName}";
         }
         $clauses[] = sprintf("MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)", implode(',', $prefixedFieldNames), $strtolower(CRM_Core_DAO::escapeString($formattedQuery)));
     } else {
         //CRM_Core_Session::setStatus(ts('Cannot use FTS for %1 (%2)', array(
         //  1 => $table,
         //  2 => implode(', ', $fullTextFields),
         //)));
         $formattedQuery = CRM_Utils_QueryFormatter::singleton()->format($queryText, CRM_Utils_QueryFormatter::LANG_SQL_LIKE);
         $escapedText = $strtolower(CRM_Core_DAO::escapeString($formattedQuery));
         foreach ($fullTextFields as $fieldName) {
             $clauses[] = "{$tableAlias}.{$fieldName} LIKE '{$escapedText}'";
         }
     }
     return implode(' OR ', $clauses);
 }
Beispiel #3
0
 /**
  * (Setting Callback)
  * Respond to changes in the "enable_innodb_fts" setting
  *
  * @param bool $oldValue
  * @param bool $newValue
  * @param array $metadata
  *   Specification of the setting (per *.settings.php).
  */
 public static function onToggleFts($oldValue, $newValue, $metadata)
 {
     $indexer = CRM_Core_InnoDBIndexer::singleton();
     $indexer->setActive($newValue);
     $indexer->fixSchemaDifferences();
 }