Skip to content

Commit

Permalink
- Patch #124980 by jhodgdon: Indexer is removing ... and -- instead o…
Browse files Browse the repository at this point in the history
…f replacing with a space.
  • Loading branch information
dbuytaert committed Jul 22, 2010
1 parent 19c7193 commit d79dff0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
9 changes: 6 additions & 3 deletions modules/search/search.module
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ function search_simplify($text) {
// Readable regexp: ([number]+)[punctuation]+(?=[number])
$text = preg_replace('/([' . PREG_CLASS_NUMBERS . ']+)[' . PREG_CLASS_PUNCTUATION . ']+(?=[' . PREG_CLASS_NUMBERS . '])/u', '\1', $text);

// Multiple dot and dash groups are word boundaries and replaced with space.
// No need to use the unicode modifer here because 0-127 ASCII characters
// can't match higher UTF-8 characters as the leftmost bit of those are 1.
$text = preg_replace('/[.-]{2,}/', ' ', $text);

// The dot, underscore and dash are simply removed. This allows meaningful
// search behavior with acronyms and URLs. No need to use the unicode modifer
// here because 0-127 ASCII characters can't match higher UTF-8 characters as
// the leftmost bit of those are 1.
// search behavior with acronyms and URLs. See unicode note directly above.
$text = preg_replace('/[._-]+/', '', $text);

// With the exception of the rules above, we consider all punctuation,
Expand Down
25 changes: 21 additions & 4 deletions modules/search/search.test
Original file line number Diff line number Diff line change
Expand Up @@ -935,22 +935,22 @@ class SearchCommentCountToggleTestCase extends DrupalWebTestCase {
$this->drupalPost('', $edit, t('Search'));
$this->assertNoText(t('0 comments'), t('Empty comment count does not display for nodes with comment status set to Hidden'));
$this->assertNoText(t('1 comment'), t('Non-empty comment count does not display for nodes with comment status set to Hidden'));
}
}
}

/**
* Test search_simplify() on every Unicode character.
* Test search_simplify() on every Unicode character, and some other cases.
*/
class SearchSimplifyTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Search simplify',
'description' => 'Check that simplification works as intended.',
'description' => 'Check that the search_simply() function works as intended.',
'group' => 'Search',
);
}

function testSearchSimplify() {
function testSearchSimplifyUnicode() {
$input = file_get_contents(DRUPAL_ROOT . '/modules/search/tests/UnicodeTest.txt');
$strings = explode(chr(10), $input);
foreach ($strings as $key => $string) {
Expand All @@ -969,6 +969,23 @@ class SearchSimplifyTestCase extends DrupalWebTestCase {
// Diff really does not like files starting with \0 so test it separately.
$this->assertIdentical(' ', search_simplify($string), t('Search simplify works for ASCII control characters.'));
}

/**
* Tests that search_simplify() does the right thing with punctuation.
*/
function testSearchSimplifyPunctuation() {
$cases = array(
array('20.03/94-28,876', '20039428876', 'Punctuation removed from numbers'),
array('great...drupal--module', 'great drupal module', 'Multiple dot and dashes are word boundaries'),
array('very_great-drupal.module', 'verygreatdrupalmodule', 'Single dot, dash, underscore are removed'),
array('regular,punctuation;word', 'regular punctuation word', 'Punctuation is a word boundary'),
);

foreach ($cases as $case) {
$out = trim(search_simplify($case[0]));
$this->assertEqual($out, $case[1], $case[2]);
}
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion profiles/minimal/minimal.profile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// $Id$

/**
* Implements hook_form_alter().
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function minimal_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
}
10 changes: 4 additions & 6 deletions profiles/standard/standard.profile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// $Id$

/**
* Implements hook_form_alter().
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function standard_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'install_configure_form') {
// Set default for site name field.
$form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
}
function standard_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
}

0 comments on commit d79dff0

Please sign in to comment.