Merge remote-tracking branch 'dhruv/ticket/11040' into develop

* dhruv/ticket/11040:
  [ticket/11040] Topic is deleted if test is skipped
  [ticket/11040] Use unique text for the test post added
  [ticket/11040] Use hard delete in delete_topic
  [ticket/11040] Add migration to drop postgres search indexes
  [ticket/11040] Delete the functional test topic to avoid conflicts
  [ticket/11040] Add methods to delete post and topic in functional tests
  [ticket/11040] Swap post_text and post_subject for post_content index
  [ticket/11040] Add test cases for searching subject and post content together
  [ticket/11040] Remove postgres extra indexes
  [ticket/11040] Add post_content index
  [ticket/11040] Search subject and text together
This commit is contained in:
Joas Schilling 2014-03-14 10:13:42 +01:00
commit 5f8f1f04fd
4 changed files with 115 additions and 19 deletions

View file

@ -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',
),
),
);
}
}

View file

@ -457,15 +457,13 @@ class fulltext_postgres extends \phpbb\search\base
$sql_where_options .= $sql_match_where; $sql_where_options .= $sql_match_where;
$tmp_sql_match = array(); $tmp_sql_match = array();
foreach (explode(',', $sql_match) as $sql_match_column) $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) . "')";
$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) . "')";
}
$this->db->sql_transaction('begin'); $this->db->sql_transaction('begin');
$sql_from = "FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p"; $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_where_options";
$sql = "SELECT $sql_select $sql = "SELECT $sql_select
$sql_from $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))"); $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); $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']); $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); $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
@ -846,7 +844,7 @@ class fulltext_postgres extends \phpbb\search\base
$this->get_stats(); $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,14 +886,14 @@ class fulltext_postgres extends \phpbb\search\base
// deal with older PostgreSQL versions which didn't use Index_type // deal with older PostgreSQL versions which didn't use Index_type
if (strpos($row['indexdef'], 'to_tsvector') !== false) 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;
}
else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
{ {
$this->stats['post_subject'] = $row; $this->stats['post_subject'] = $row;
} }
else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_content' || $row['relname'] == POSTS_TABLE . '_post_content')
{
$this->stats['post_content'] = $row;
}
} }
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);

View file

@ -12,11 +12,11 @@
*/ */
abstract class phpbb_functional_search_base extends phpbb_functional_test_case 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); $crawler = self::request('GET', 'search.php?keywords=' . $keywords);
$this->assertEquals(1, $crawler->filter('.postbody')->count()); $this->assertEquals($posts_found, $crawler->filter('.postbody')->count());
$this->assertEquals(3, $crawler->filter('.posthilit')->count()); $this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count());
} }
protected function assert_search_not_found($keywords) 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->login();
$this->admin_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); $crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form(); $form = $crawler->selectButton('Submit')->form();
$values = $form->getValues(); $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 // check if search backend is not supported
if ($crawler->filter('.errorbox')->count() > 0) if ($crawler->filter('.errorbox')->count() > 0)
{ {
$this->delete_topic($post['topic_id']);
$this->markTestSkipped("Search backend is not supported/running"); $this->markTestSkipped("Search backend is not supported/running");
} }
$this->create_search_index(); $this->create_search_index();
} }
$this->logout(); $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->assert_search_not_found('loremipsumdedo');
$this->login(); $this->login();
$this->admin_login(); $this->admin_login();
$this->delete_search_index(); $this->delete_search_index();
$this->delete_topic($post['topic_id']);
} }
protected function create_search_index() protected function create_search_index()

View file

@ -1003,6 +1003,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 * Returns the requested parameter from a URL
* *