From f4645a63762749b2c3d196c57db5a10cc93b04ca Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 24 Jun 2012 20:15:01 +0530 Subject: [PATCH 1/6] [ticket/10945] remove trigger_error call removes trigger_error call incase no search results are found or start variable exceeds the amount. So that search query is displayed in the search box even if no results are returned. PHPBB3-10945 --- phpBB/search.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index ad9c371f63..0f13dbbfa0 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -540,12 +540,6 @@ if ($keywords || $author || $author_id || $search_id || $submit) $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); } - // For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. - if (!sizeof($id_ary) && !$search_id) - { - trigger_error('NO_SEARCH_RESULTS'); - } - $sql_where = ''; if (sizeof($id_ary)) From b6eec5c142da665248a914ef2d47aad3f2367f4b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 4 Nov 2013 15:34:52 +0530 Subject: [PATCH 2/6] [ticket/10945] Display search query when search fails in native search If search fails and common words are present, split_keywords returns false and search.php file prints appropriate message of common words. If search fails and there are no common words, split_keywords returns true and keyword_search returns false so that the search query is displayed in search box. PHPBB3-10945 --- phpBB/includes/search/fulltext_native.php | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index dc961f3c8a..5e116efebc 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -357,22 +357,6 @@ class fulltext_native extends search_backend $this->{$mode . '_ids'}[] = $words[$word]; } } - // throw an error if we shall not ignore unexistant words - else if (!$ignore_no_id) - { - if (!isset($common_ids[$word])) - { - $len = utf8_strlen($word); - if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) - { - trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word)); - } - else - { - $this->common_words[] = $word; - } - } - } else { $len = utf8_strlen($word); @@ -383,8 +367,11 @@ class fulltext_native extends search_backend } } - // we can't search for negatives only - if (!sizeof($this->must_contain_ids)) + // If common words are present and no other search results then return false + // search.php will print out appropriate error message. + // If both common words and search results are empty return true and keyword_search() + // later will return false for that condition + if (empty($this->must_contain_ids) && sizeof($this->common_words)) { return false; } @@ -428,6 +415,12 @@ class fulltext_native extends search_backend return false; } + // we can't search for negatives only + if (empty($this->must_contain_ids)) + { + return false; + } + $must_contain_ids = $this->must_contain_ids; $must_not_contain_ids = $this->must_not_contain_ids; $must_exclude_one_ids = $this->must_exclude_one_ids; From c51dcbe6a0cd6e15456ac80b2bdfe13d94f27f07 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 19 Dec 2013 04:22:23 +0530 Subject: [PATCH 3/6] [ticket/10945] Fix return values for split_keywords function The function now returns false if all the words are common words and true otherwise. PHPBB3-10945 --- phpBB/includes/search/fulltext_native.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 5e116efebc..2ee119ccfe 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -231,7 +231,6 @@ class fulltext_native extends search_backend } $db->sql_freeresult($result); } - unset($exact_words); // now analyse the search query, first split it using the spaces $query = explode(' ', $keywords); @@ -359,24 +358,19 @@ class fulltext_native extends search_backend } else { - $len = utf8_strlen($word); - if ($len < $this->word_length['min'] || $len > $this->word_length['max']) + if (!isset($common_ids[$word])) { - $this->common_words[] = $word; + $len = utf8_strlen($word); + if ($len < $this->word_length['min'] || $len > $this->word_length['max']) + { + $this->common_words[] = $word; + } } } } - // If common words are present and no other search results then return false - // search.php will print out appropriate error message. - // If both common words and search results are empty return true and keyword_search() - // later will return false for that condition - if (empty($this->must_contain_ids) && sizeof($this->common_words)) - { - return false; - } - - if (!empty($this->search_query)) + // Return true if all words are not common words + if (sizeof($exact_words) - sizeof($this->common_words) > 0) { return true; } From 41fa32bae4d9f7663ab97dd7cf16b99f5b438abb Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 11 Oct 2013 16:17:55 +0530 Subject: [PATCH 4/6] [ticket/10945] Remove mark test incomplete for mysql and postgres PHPBB3-10945 --- tests/functional/search/mysql_test.php | 4 ---- tests/functional/search/postgres_test.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/tests/functional/search/mysql_test.php b/tests/functional/search/mysql_test.php index 7af8051417..52a7b14f40 100644 --- a/tests/functional/search/mysql_test.php +++ b/tests/functional/search/mysql_test.php @@ -16,8 +16,4 @@ class phpbb_functional_search_mysql_test extends phpbb_functional_search_base { protected $search_backend = '\phpbb\search\fulltext_mysql'; - protected function assert_search_not_found($keywords) - { - $this->markTestIncomplete('MySQL search when fails doesn\'t show the search query'); - } } diff --git a/tests/functional/search/postgres_test.php b/tests/functional/search/postgres_test.php index 487b8aeebb..974b417659 100644 --- a/tests/functional/search/postgres_test.php +++ b/tests/functional/search/postgres_test.php @@ -16,8 +16,4 @@ class phpbb_functional_search_postgres_test extends phpbb_functional_search_base { protected $search_backend = '\phpbb\search\fulltext_postgres'; - protected function assert_search_not_found($keywords) - { - $this->markTestIncomplete('Postgres search when fails doesn\'t show the search query'); - } } From 304c0799ba036bd318f33186f23d1ba631b07786 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 4 Nov 2013 15:58:48 +0530 Subject: [PATCH 5/6] [ticket/10945] Fix Unit Tests as per new changes to split_keywords PHPBB3-10945 --- tests/search/native_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 18c6df2445..4911160cc0 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -106,17 +106,17 @@ class phpbb_search_native_test extends phpbb_search_test_case array( '-foo', 'all', - false, - null, - null, + true, + array(), + array(1), array(), ), array( '-foo -bar', 'all', - false, - null, - null, + true, + array(), + array(1, 2), array(), ), // all common From 0036b00fc476cdc9c3c83899da98370c18b339b3 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 4 Nov 2013 16:00:49 +0530 Subject: [PATCH 6/6] [ticket/10945] Remove mark test incomplete for native search backend PHPBB3-10945 --- tests/functional/search/native_test.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/functional/search/native_test.php b/tests/functional/search/native_test.php index ce568df616..512c6f2830 100644 --- a/tests/functional/search/native_test.php +++ b/tests/functional/search/native_test.php @@ -15,9 +15,4 @@ require_once dirname(__FILE__) . '/base.php'; class phpbb_functional_search_native_test extends phpbb_functional_search_base { protected $search_backend = '\phpbb\search\fulltext_native'; - - protected function assert_search_not_found($keywords) - { - $this->markTestIncomplete('Native search when fails doesn\'t show the search query'); - } }