From 19d76f76dcd19e2bd44fbe7a384533bae4cb1538 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 12:45:18 +0530 Subject: [PATCH] [feature/postgresql-fulltext-search] remove phrase search code Unused Code for phrase search removed as pgsql doesnt support it. An added message is displayed if user tries to perform exact phrase search. PHPBB3-9730 --- phpBB/includes/search/fulltext_postgres.php | 34 +------------------ phpBB/language/en/search.php | 1 + phpBB/search.php | 10 ++++++ .../prosilver/template/search_results.html | 1 + 4 files changed, 13 insertions(+), 33 deletions(-) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index aedc62ad7a..c38dc84d7b 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -30,6 +30,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base public $search_query; public $common_words = array(); public $word_length = array(); + public $phrase_search = false; public function __construct(&$error) { @@ -110,39 +111,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base preg_match_all('#(?:[^\p{L}\p{N}*"()]|^)([+\-|]?(?:[\p{L}\p{N}*"()]+\'?)*[\p{L}\p{N}*"()])(?:[^\p{L}\p{N}*"()]|$)#u', $split_keywords, $matches); $this->split_words = $matches[1]; - // to allow phrase search, we need to concatenate quoted words - $tmp_split_words = array(); - $phrase = ''; - foreach ($this->split_words as $word) - { - if ($phrase) - { - $phrase .= ' ' . $word; - if (strpos($word, '"') !== false && substr_count($word, '"') % 2 == 1) - { - $tmp_split_words[] = $phrase; - $phrase = ''; - } - } - else if (strpos($word, '"') !== false && substr_count($word, '"') % 2 == 1) - { - $phrase = $word; - } - else - { - $tmp_split_words[] = $word . ' '; - } - } - if ($phrase) - { - $tmp_split_words[] = $phrase; - } - - $this->split_words = $tmp_split_words; - - unset($tmp_split_words); - unset($phrase); - foreach ($this->split_words as $i => $word) { $clean_word = preg_replace('#^[+\-|"]#', '', $word); diff --git a/phpBB/language/en/search.php b/phpBB/language/en/search.php index 5b6fdce0e7..2fbb5122ad 100644 --- a/phpBB/language/en/search.php +++ b/phpBB/language/en/search.php @@ -72,6 +72,7 @@ $lang = array_merge($lang, array( 'WORDS_IN_NO_POST' => 'No posts were found because the words %s are not contained in any post.', 'POST_CHARACTERS' => 'characters of posts', + 'PHRASE_SEARCH_DISABLED' => 'Searching by exact phrase is not supported on this board.', 'RECENT_SEARCHES' => 'Recent searches', 'RESULT_DAYS' => 'Limit results to previous', diff --git a/phpBB/search.php b/phpBB/search.php index 2b463aec9c..0d13644b02 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -596,6 +596,13 @@ if ($keywords || $author || $author_id || $search_id || $submit) $u_search .= ($search_fields != 'all') ? '&sf=' . $search_fields : ''; $u_search .= ($return_chars != 300) ? '&ch=' . $return_chars : ''; + //check if search backend supports phrase search or not + $l_phrase_search_disabled = ''; + if (strpos(html_entity_decode($keywords), '"') !== false && isset($search->phrase_search)) + { + $l_phrase_search_disabled = $search->phrase_search ? false : true; + } + $template->assign_vars(array( 'SEARCH_TITLE' => $l_search_title, 'SEARCH_MATCHES' => $l_search_matches, @@ -603,6 +610,9 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'IGNORED_WORDS' => (sizeof($search->common_words)) ? implode(' ', $search->common_words) : '', 'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start), 'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start), + + 'PHRASE_SEARCH_DISABLED' => $l_phrase_search_disabled, + 'TOTAL_MATCHES' => $total_match_count, 'SEARCH_IN_RESULTS' => ($search_id) ? false : true, diff --git a/phpBB/styles/prosilver/template/search_results.html b/phpBB/styles/prosilver/template/search_results.html index 5d75bd3d56..56712db75a 100644 --- a/phpBB/styles/prosilver/template/search_results.html +++ b/phpBB/styles/prosilver/template/search_results.html @@ -2,6 +2,7 @@

{SEARCH_TITLE}{SEARCH_MATCHES}: {SEARCH_WORDS}

{L_IGNORED_TERMS}: {IGNORED_WORDS}

+

{L_PHRASE_SEARCH_DISABLED}

{L_RETURN_TO}: {SEARCH_TOPIC}