aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/db/migration/data/v310/postgres_fulltext_drop.php47
-rw-r--r--phpBB/phpbb/search/fulltext_postgres.php26
-rw-r--r--tests/functional/search/base.php13
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php46
4 files changed, 114 insertions, 18 deletions
diff --git a/phpBB/phpbb/db/migration/data/v310/postgres_fulltext_drop.php b/phpBB/phpbb/db/migration/data/v310/postgres_fulltext_drop.php
new file mode 100644
index 0000000000..7d4aea3c95
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v310/postgres_fulltext_drop.php
@@ -0,0 +1,47 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\db\migration\data\v310;
+
+class postgres_fulltext_drop extends \phpbb\db\migration\migration
+{
+ public function effectively_installed()
+ {
+ // This migration is irrelevant for all non-PostgreSQL DBMSes.
+ return strpos($this->db->sql_layer, 'postgres') === false;
+ }
+
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v310\dev',
+ );
+ }
+
+ public function update_schema()
+ {
+ /*
+ * Drop FULLTEXT indexes related to PostgreSQL fulltext search.
+ * Doing so is equivalent to dropping the search index from the ACP.
+ * Possibly time-consuming recreation of the search index (i.e.
+ * FULLTEXT indexes) is left as a task to the admin to not
+ * unnecessarily stall the upgrade process. The new search index will
+ * then require about 40% less table space (also see PHPBB3-11040).
+ */
+ return array(
+ 'drop_keys' => array(
+ $this->table_prefix . 'posts' => array(
+ 'post_subject',
+ 'post_text',
+ 'post_content',
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/search/fulltext_postgres.php b/phpBB/phpbb/search/fulltext_postgres.php
index 063bf52a19..63caeffcc5 100644
--- a/phpBB/phpbb/search/fulltext_postgres.php
+++ b/phpBB/phpbb/search/fulltext_postgres.php
@@ -457,15 +457,13 @@ class fulltext_postgres extends \phpbb\search\base
$sql_where_options .= $sql_match_where;
$tmp_sql_match = array();
- foreach (explode(',', $sql_match) as $sql_match_column)
- {
- $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')";
- }
+ $sql_match = str_replace(',', " || ' ' ||", $sql_match);
+ $tmp_sql_match = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')";
$this->db->sql_transaction('begin');
$sql_from = "FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p";
- $sql_where = "WHERE (" . implode(' OR ', $tmp_sql_match) . ")
+ $sql_where = "WHERE (" . $tmp_sql_match . ")
$sql_where_options";
$sql = "SELECT $sql_select
$sql_from
@@ -793,9 +791,9 @@ class fulltext_postgres extends \phpbb\search\base
$this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))");
}
- if (!isset($this->stats['post_text']))
+ if (!isset($this->stats['post_content']))
{
- $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text))");
+ $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_content ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text || ' ' || post_subject))");
}
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
@@ -826,9 +824,9 @@ class fulltext_postgres extends \phpbb\search\base
$this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']);
}
- if (isset($this->stats['post_text']))
+ if (isset($this->stats['post_content']))
{
- $this->db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']);
+ $this->db->sql_query('DROP INDEX ' . $this->stats['post_content']['relname']);
}
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
@@ -846,7 +844,7 @@ class fulltext_postgres extends \phpbb\search\base
$this->get_stats();
}
- return (isset($this->stats['post_text']) && isset($this->stats['post_subject'])) ? true : false;
+ return (isset($this->stats['post_subject']) && isset($this->stats['post_content'])) ? true : false;
}
/**
@@ -888,13 +886,13 @@ class fulltext_postgres extends \phpbb\search\base
// deal with older PostgreSQL versions which didn't use Index_type
if (strpos($row['indexdef'], 'to_tsvector') !== false)
{
- if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text')
+ if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
{
- $this->stats['post_text'] = $row;
+ $this->stats['post_subject'] = $row;
}
- else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
+ else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_content' || $row['relname'] == POSTS_TABLE . '_post_content')
{
- $this->stats['post_subject'] = $row;
+ $this->stats['post_content'] = $row;
}
}
}
diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php
index 28327da914..0bd9bf01ab 100644
--- a/tests/functional/search/base.php
+++ b/tests/functional/search/base.php
@@ -12,11 +12,11 @@
*/
abstract class phpbb_functional_search_base extends phpbb_functional_test_case
{
- protected function assert_search_found($keywords)
+ protected function assert_search_found($keywords, $posts_found, $words_highlighted)
{
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
- $this->assertEquals(1, $crawler->filter('.postbody')->count());
- $this->assertEquals(3, $crawler->filter('.posthilit')->count());
+ $this->assertEquals($posts_found, $crawler->filter('.postbody')->count());
+ $this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count());
}
protected function assert_search_not_found($keywords)
@@ -32,6 +32,8 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->login();
$this->admin_login();
+ $post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
+
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
@@ -49,18 +51,21 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
// check if search backend is not supported
if ($crawler->filter('.errorbox')->count() > 0)
{
+ $this->delete_topic($post['topic_id']);
$this->markTestSkipped("Search backend is not supported/running");
}
$this->create_search_index();
}
$this->logout();
- $this->assert_search_found('phpbb3+installation');
+ $this->assert_search_found('phpbb3+installation', 1, 3);
+ $this->assert_search_found('foosubject+barsearch', 1, 2);
$this->assert_search_not_found('loremipsumdedo');
$this->login();
$this->admin_login();
$this->delete_search_index();
+ $this->delete_topic($post['topic_id']);
}
protected function create_search_index()
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index a1a4ed73e2..d6eb4a632f 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -1004,6 +1004,52 @@ class phpbb_functional_test_case extends phpbb_test_case
}
/**
+ * Deletes a topic
+ *
+ * Be sure to login before creating
+ *
+ * @param int $topic_id
+ * @return null
+ */
+ public function delete_topic($topic_id)
+ {
+ $crawler = self::request('GET', "viewtopic.php?t={$topic_id}&sid={$this->sid}");
+
+ $this->add_lang('posting');
+ $form = $crawler->selectButton('Go')->eq(1)->form();
+ $form['action']->select('delete_topic');
+ $crawler = self::submit($form);
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $form['delete_permanent'] = 1;
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+ }
+
+ /**
+ * Deletes a post
+ *
+ * Be sure to login before creating
+ *
+ * @param int $forum_id
+ * @param int $topic_id
+ * @return null
+ */
+ public function delete_post($forum_id, $post_id)
+ {
+ $this->add_lang('posting');
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$forum_id}&p={$post_id}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $form['delete_permanent'] = 1;
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+ }
+
+ /**
* Returns the requested parameter from a URL
*
* @param string $url