=== modified file 'fuzzysearch/fuzzysearch.install' --- fuzzysearch/fuzzysearch.install 2008-11-05 23:12:12 +0000 +++ fuzzysearch/fuzzysearch.install 2008-11-05 23:24:44 +0000 @@ -1,5 +1,9 @@ nid, $module, time()); } } - drupal_set_message('Fuzzysearch Module Installed Successfully.'); - drupal_set_message('Content queued for indexing, please run cron to begin indexing.'); + drupal_set_message(get_t('Fuzzysearch Module Installed Successfully.')); + drupal_set_message(get_t('Content queued for indexing, please run cron to begin indexing.')); variable_set('search_nlength', 3); } function fuzzysearch_uninstall() { - switch($GLOBALS['db_type']) { + switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': db_query("DROP TABLE IF EXISTS {search_index_queue}, {search_fuzzy_index}"); @@ -48,5 +52,5 @@ // TODO insert postgres table removal break; } - drupal_set_message('Fuzzy Search Module successfully removed'); + drupal_set_message(get_t('Fuzzy Search Module successfully removed')); } === modified file 'fuzzysearch/fuzzysearch.module' --- fuzzysearch/fuzzysearch.module 2008-11-05 23:12:12 +0000 +++ fuzzysearch/fuzzysearch.module 2008-11-05 23:26:20 +0000 @@ -1,6 +1,9 @@ 'checkbox', '#title' => t('Display Scoring'), '#description' => t('If selected, the completeness and score of the results will be shown below each result'), - '#default_value' => variable_get('search_debug_score', false) + '#default_value' => variable_get('search_debug_score', FALSE) ); $form['update']['completeness'] = array( @@ -168,7 +171,7 @@ while ($row = db_fetch_object($query)) { fuzzysearch_reindex($row->nid, 'fuzzysearch'); } - drupal_set_message('Nodes ready for reindexing, please run cron to update the index.'); + drupal_set_message(t('Nodes ready for reindexing, please run cron to update the index.')); } variable_set('search_min_completeness', $form_state['values']['completeness']); variable_set('search_debug_score', $form_state['values']['debug_score']); @@ -176,7 +179,7 @@ /** - * Implementation of hook_nodeapi() + * Implementation of hook_nodeapi(). * * Used to remove node data from index upon deletion and * queue a node for indexing on insertion @@ -225,7 +228,7 @@ // Return all the score modifiers using hook_search_score // expects each score modifier to return an array defining the title and description // of the modifier - $scores = module_invoke_all('search_score', 'settings', null); + $scores = module_invoke_all('search_score', 'settings', NULL); foreach ($scores as $key => $score) { $form_index = $score['id']; @@ -255,7 +258,7 @@ variable_set('search_scoring_'. $key, $value); } } - drupal_set_message('Score factor multipliers have been updated'); + drupal_set_message(t('Score factor multipliers have been updated')); } /** @@ -273,7 +276,7 @@ /** - * Implementation of hook_cron + * Implementation of hook_cron(). * We use this query to find all the nodes that need to be indexed or * reindexed. Instead of the normal search module which uses timestamps to * find out which nodes need indexing this allows other modules to specify @@ -281,7 +284,7 @@ * timestamp */ function fuzzysearch_cron() { - $query = db_query("SELECT nid FROM {search_index_queue} LIMIT 0, 150"); + $query = db_query_range("SELECT nid FROM {search_index_queue}", 0, 150); while ($result = db_fetch_object($query)) { fuzzysearch_index($result->nid); } @@ -310,10 +313,10 @@ $text .= $node->body; // Implementation of nodeapi's update_index op. - $outside_text = module_invoke_all('nodeapi', $node, 'update index', null, null); + $outside_text = module_invoke_all('nodeapi', $node, 'update index', NULL, NULL); if ($outside_text) { foreach ($outside_text as $content) { - $text .= ' '.$content; + $text .= ' '. $content; } } @@ -338,7 +341,7 @@ $text = strip_tags($text, '<'. implode('><', array_keys($tags)) .'>'); // Strip all stop words if stop words are enabled - if (variable_get('search_stop_words', false)) { + if (variable_get('search_stop_words', FALSE)) { module_invoke_all('search_filter', &$text); } @@ -414,7 +417,7 @@ * @param $word_score: score given to the word based on the tag it is in * @param $node_score: score modifier given to the node from hook_search_score */ -function fuzzysearch_index_insert($word, $word_id, $nid, $word_score, $node_score){ +function fuzzysearch_index_insert($word, $word_id, $nid, $word_score, $node_score) { $length = fuzzysearch_utf8_strlen($word); $nlength = variable_get('search_nlength', 3); // Ensure that having all score modifiers set to 0 will not affect our natural scoring @@ -429,7 +432,7 @@ // Calculate how complete the ngram is compared to the length of the word $completeness = 100 / ($length - $nlength + 1); // Create ngrams and index them - for ($i=0; $i < ($length - $nlength + 1); $i++) { + for ($i = 0; $i < ($length - $nlength + 1); $i++) { db_query("INSERT INTO {search_fuzzy_index} (nid, word_id, ngram, completeness, score) VALUES (%d, %d, '%s', %f, %f)", $nid, $word_id, fuzzysearch_utf8_substr($word, $i, $nlength), $completeness, $score); } @@ -449,17 +452,17 @@ function fuzzysearch_cleanse($text) { $text = strip_tags($text); $text = strtolower($text); - return preg_replace('/['. PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $text); + return preg_replace('/['. PREG_CLASS_SEARCH_EXCLUDE .']+/u', ' ', $text); } /** * Helper function to split UTF8 characters * Credits: posted on php.net by: www.yeap.lv */ -function fuzzysearch_utf8_substr($str,$from,$len) { - return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. - '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', - '$1',$str); +function fuzzysearch_utf8_substr($str, $from, $len) { + return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'. $from .'}'. + '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'. $len .'}).*#s', + '$1', $str); } /** @@ -553,7 +556,7 @@ function fuzzysearch_process($query) { global $user; // if no keys were entered do not display anything below the search form - if(!$query){ + if (!$query) { return; } $nlength = variable_get('search_nlength', 3); @@ -577,12 +580,12 @@ $comp = 1 / ($length - 2 - $nlength + 1); } $comp = number_format($comp + .001, 3) * 100; - for ($i=0; $i < $length - 2; $i++) { + for ($i = 0; $i < $length - 2; $i++) { $clause .= " (ngram = '". fuzzysearch_utf8_substr($word, $i, $nlength) ."' AND completeness <". $comp .") OR"; // $keys[] = fuzzysearch_utf8_substr($word, $i, $nlength); } } - else{ + else { $clause .= " ngram = '". $word ."' OR"; } } @@ -600,7 +603,15 @@ // TODO: Fix the minimum completeness so that a single qgram match doesn't necessarily return a match $min_completeness = check_plain(variable_get('search_min_completeness', 40)); // if($user->uid == 1){ - $query = pager_query(db_rewrite_sql("SELECT n.nid, SUM(percent) AS completeness, SUM(score) AS score FROM (SELECT n.nid, SUM(completeness) percent, SUM(score) score FROM {search_fuzzy_index} AS s LEFT JOIN {node} AS n ON (n.nid = s.nid) WHERE (($clause) AND n.status = 1) GROUP BY word_id HAVING percent > $min_completeness) AS n GROUP BY n.nid ORDER BY completeness DESC, score DESC"), 10, 0, "SELECT COUNT(DISTINCT(n.nid)) FROM (SELECT n.nid, CEILING(SUM(completeness)) completeness, SUM(score) score FROM {search_fuzzy_index} AS n WHERE $clause GROUP BY word_id HAVING SUM(completeness) > $min_completeness ORDER BY completeness DESC, score DESC) AS n"); + $query = pager_query(db_rewrite_sql("SELECT n.nid, SUM(percent) AS completeness, SUM(score) AS score FROM (SELECT n.nid, SUM(completeness) percent, SUM(score) score + FROM {search_fuzzy_index} AS s LEFT JOIN {node} AS n ON (n.nid = s.nid) + WHERE (($clause) AND n.status = 1) + GROUP BY word_id HAVING percent > $min_completeness) + AS n GROUP BY n.nid ORDER BY completeness DESC, score DESC"), + 10, 0, "SELECT COUNT(DISTINCT(n.nid)) FROM (SELECT n.nid, CEILING(SUM(completeness)) completeness, SUM(score) score + FROM {search_fuzzy_index} AS n + WHERE $clause GROUP BY word_id HAVING SUM(completeness) > $min_completeness + ORDER BY completeness DESC, score DESC) AS n"); // } // else { // $query = pager_query(db_rewrite_sql("SELECT n.nid, CEILING(SUM(completeness)) AS completeness, SUM(score) AS score FROM ((SELECT n.nid, SUM(completeness) completeness, SUM(score) score FROM {search_fuzzy_index} AS n WHERE $clause GROUP BY word_id HAVING SUM(completeness) > $min_completeness ORDER BY completeness DESC, score DESC) AS n GROUP BY n.nid ORDER BY CEILING(SUM(completeness)) DESC, score DESC"), 10, 0, "SELECT COUNT(DISTINCT(n.nid)) FROM (SELECT n.nid, CEILING(SUM(completeness)) completeness, SUM(score) score FROM {search_fuzzy_index} AS n WHERE $clause GROUP BY word_id HAVING SUM(completeness) > $min_completeness ORDER BY completeness DESC, score DESC) AS n"); @@ -647,7 +658,7 @@ $output .= '
'. l(t($result->title), 'node/'. $result->nid) .'
'; $output .= '
'; $output .= '

'. $result->teaser .'

'; - if (variable_get('search_debug_score', false)) { + if (variable_get('search_debug_score', FALSE)) { $output .= '

Completeness: '. $result->completeness .' Score: '. $result->score .'

'; } $output .= '
';