diff --git a/.travis.yml b/.travis.yml index 2d61b17c9c..519031bc78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_script: - tar xzf sphinx-2.0.6-release.tar.gz - sh -c "cd sphinx-2.0.6-release && wget http://snowball.tartarus.org/dist/libstemmer_c.tgz && tar xzf libstemmer_c.tgz && ./configure --with-libstemmer --with-iconv --with-mysql --enable-id64 --quiet && make --quiet && sudo make install" - sudo mkdir -p /var/sphinx/datas - - sudo chmod 0777 /var/sphinx + - sudo chmod -R 0777 /var/sphinx - mysql -e 'create database ab_test;create database db_test; create database ab_unitTests; create database db_unitTests;' - sudo mysql -e "GRANT ALL PRIVILEGES ON ab_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION" - sudo mysql -e "GRANT ALL PRIVILEGES ON db_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION" diff --git a/lib/Alchemy/Phrasea/Border/Attribute/Status.php b/lib/Alchemy/Phrasea/Border/Attribute/Status.php index c650bbc653..09507504f0 100644 --- a/lib/Alchemy/Phrasea/Border/Attribute/Status.php +++ b/lib/Alchemy/Phrasea/Border/Attribute/Status.php @@ -37,7 +37,7 @@ class Status implements AttributeInterface } else { throw new \InvalidArgumentException('Invalid status argument'); } - + $this->status = $status; } diff --git a/lib/Alchemy/Phrasea/Border/Manager.php b/lib/Alchemy/Phrasea/Border/Manager.php index 1fff81cfec..8422aac680 100644 --- a/lib/Alchemy/Phrasea/Border/Manager.php +++ b/lib/Alchemy/Phrasea/Border/Manager.php @@ -340,8 +340,7 @@ class Manager } break; case AttributeInterface::NAME_STATUS: - - $element->set_binary_status($element->get_status() | $attribute->getValue()); + $element->set_binary_status(decbin(bindec($element->get_status()) | bindec($attribute->getValue()))); break; case AttributeInterface::NAME_STORY: diff --git a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php index cdce9bc04a..ccb0156e60 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php @@ -489,8 +489,8 @@ searchd # listen = 192.168.0.1:9312 # listen = 9312 # listen = /var/run/searchd.sock - listen = 9306 - listen = 9308:mysql41 + listen = 127.0.0.1:19306 + listen = 127.0.0.1:19308:mysql41 # log file, searchd run info is logged here # optional, default is \'searchd.log\' diff --git a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php index 95caa66f36..d4d50c0a84 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php @@ -117,7 +117,7 @@ class SphinxSearchEngine implements SearchEngineInterface for ($i = 4; $i < 32; $i++) { if ($binStatus[$i]) { - $status[] = crc32($record->get_databox()->get_sbas_id() . '_' . $i); + $status[] = sprintf("%u", crc32($record->get_databox()->get_sbas_id() . '_' . $i)); } } @@ -126,13 +126,12 @@ class SphinxSearchEngine implements SearchEngineInterface continue; } - if (!$field->get_databox_field()->isBusiness()) { + if (!$field->get_databox_field()->isBusiness()) { $all_datas[] = $field->get_serialized_values(); } foreach ($field->get_values() as $value) { - - $sql = "REPLACE INTO " + $this->rt_conn->exec("REPLACE INTO " . "metas_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES ( '" . $value->getId() . "' ,'" . str_replace("'", "\'", $value->getValue()) . "' @@ -141,21 +140,19 @@ class SphinxSearchEngine implements SearchEngineInterface ," . $record->get_sbas_id() . " ," . $record->get_collection()->get_coll_id() . " ," . (int) $record->is_grouping() . " - ," . crc32($record->get_sbas_id() . '_' . $value->getDatabox_field()->get_id()) . " - ," . crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id()) . " - ," . crc32($record->get_sbas_id() . '_' . $record->get_record_id()) . " - ," . crc32($record->get_type()) . " + ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $value->getDatabox_field()->get_id())) . " + ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id())) . " + ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_record_id())) . " + ," . sprintf("%u", crc32($record->get_type())) . " ,0 ," . (int) $value->getDatabox_field()->isBusiness() . " - ," . crc32($record->get_collection()->get_coll_id() . '_' . (int) $value->getDatabox_field()->isBusiness()) . " + ," . sprintf("%u", crc32($record->get_collection()->get_coll_id() . '_' . (int) $value->getDatabox_field()->isBusiness())) . " ," . $record->get_creation_date()->format('U') . " - ,(" . implode(',', $status) . ") )"; - - $this->rt_conn->exec($sql); + ,(" . implode(',', $status) . ") )"); } } - $this->rt_conn->exec("REPLACE INTO " + $sql = "REPLACE INTO " . "docs_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES ( '" . $record->get_record_id() . "' ,'" . str_replace("'", "\'", implode(' ', $all_datas)) . "' @@ -163,13 +160,15 @@ class SphinxSearchEngine implements SearchEngineInterface ," . $record->get_sbas_id() . " ," . $record->get_collection()->get_coll_id() . " ," . (int) $record->is_grouping() . " - ," . crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id()) . " - ," . crc32($record->get_sbas_id() . '_' . $record->get_record_id()) . " - ," . crc32($record->get_type()) . " + ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id())) . " + ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_record_id())) . " + ," . sprintf("%u", crc32($record->get_type())) . " ,0 ," . $record->get_creation_date()->format('U') . " - ,(" . implode(',', $status) . ") )"); - + ,(" . implode(',', $status) . ") )"; + + $this->rt_conn->exec($sql); + return $this; } @@ -388,13 +387,13 @@ class SphinxSearchEngine implements SearchEngineInterface */ public function CRCdatabox(\databox $databox) { - return crc32( + return sprintf("%u", crc32( str_replace( array('.', '%') , '_' , sprintf('%s_%s_%s_%s', $databox->get_host(), $databox->get_port(), $databox->get_user(), $databox->get_dbname()) ) - ); + )); } /** @@ -412,7 +411,7 @@ class SphinxSearchEngine implements SearchEngineInterface $filters = array(); foreach ($options->collections() as $collection) { - $filters[] = crc32($collection->get_databox()->get_sbas_id() . '_' . $collection->get_coll_id()); + $filters[] = sprintf("%u", crc32($collection->get_databox()->get_sbas_id() . '_' . $collection->get_coll_id())); } $this->sphinx->SetFilter('crc_sbas_coll', $filters); @@ -425,7 +424,7 @@ class SphinxSearchEngine implements SearchEngineInterface $filters = array(); foreach ($options->fields() as $field) { - $filters[] = crc32($field->get_databox()->get_sbas_id() . '_' . $field->get_id()); + $filters[] = sprintf("%u", crc32($field->get_databox()->get_sbas_id() . '_' . $field->get_id())); } $this->sphinx->SetFilter('crc_struct_id', $filters); @@ -436,8 +435,8 @@ class SphinxSearchEngine implements SearchEngineInterface $crc_coll_business = array(); foreach ($options->businessFieldsOn() as $collection) { - $crc_coll_business[] = crc32($collection->get_coll_id() . '_1'); - $crc_coll_business[] = crc32($collection->get_coll_id() . '_0'); + $crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_1')); + $crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_0')); } $non_business = array(); @@ -452,7 +451,7 @@ class SphinxSearchEngine implements SearchEngineInterface } foreach ($non_business as $collection) { - $crc_coll_business[] = crc32($collection->get_coll_id() . '_0'); + $crc_coll_business[] = sprintf("%u", crc32($collection->get_coll_id() . '_0')); } $this->sphinx->SetFilter('crc_coll_business', $crc_coll_business); @@ -470,14 +469,14 @@ class SphinxSearchEngine implements SearchEngineInterface continue; if (!array_key_exists($databox->get_sbas_id(), $status_opts[$n])) continue; - $crc = crc32($databox->get_sbas_id() . '_' . $n); + $crc = sprintf("%u", crc32($databox->get_sbas_id() . '_' . $n)); $this->sphinx->SetFilter('status', array($crc), ($status_opts[$n][$databox->get_sbas_id()] == '0')); } } if ($options->getRecordType()) { - $this->sphinx->SetFilter('crc_type', array(crc32($options->getRecordType()))); + $this->sphinx->SetFilter('crc_type', array(sprintf("%u", crc32($options->getRecordType())))); } diff --git a/lib/classes/module/console/sphinxGenerateSuggestion.class.php b/lib/classes/module/console/sphinxGenerateSuggestion.class.php index 9e9c9387e3..35a7439316 100644 --- a/lib/classes/module/console/sphinxGenerateSuggestion.class.php +++ b/lib/classes/module/console/sphinxGenerateSuggestion.class.php @@ -41,13 +41,13 @@ class module_console_sphinxGenerateSuggestion extends Command $params = phrasea::sbas_params($this->container); foreach ($params as $sbas_id => $p) { - $index = crc32( + $index = sprintf("%u", crc32( str_replace( array('.', '%') , '_' , sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname']) ) - ); + )); $tmp_file = $this->container['phraseanet.registry']->get('GV_RootPath') . 'tmp/dict' . $index . '.txt'; diff --git a/lib/classes/sphinx/configuration.class.php b/lib/classes/sphinx/configuration.class.php index 97efa66b99..529a280cd3 100644 --- a/lib/classes/sphinx/configuration.class.php +++ b/lib/classes/sphinx/configuration.class.php @@ -137,7 +137,7 @@ class sphinx_configuration foreach ($lb as $id => $params) { $serialized = str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])); - $index_crc = crc32($serialized); + $index_crc = sprintf("%u", crc32($serialized)); $conf .= ' diff --git a/lib/conf.d/bases_structure.xml b/lib/conf.d/bases_structure.xml index 7988c0b576..a1f8102ec2 100644 --- a/lib/conf.d/bases_structure.xml +++ b/lib/conf.d/bases_structure.xml @@ -118,7 +118,7 @@ server_coll_id - bigint(20) + int(11) unsigned 0 @@ -1076,7 +1076,7 @@ id - bigint(11) unsigned + int(11) unsigned auto_increment @@ -1211,7 +1211,7 @@ mask_and - bigint(20) unsigned + int(11) unsigned @@ -1222,7 +1222,7 @@ mask_xor - bigint(20) unsigned + int(11) unsigned @@ -1903,7 +1903,7 @@ sbas_id - bigint(11) unsigned + int(11) unsigned @@ -1911,7 +1911,7 @@ usr_id - bigint(11) unsigned + int(11) unsigned @@ -3541,7 +3541,7 @@ ord - bigint(11) unsigned + int(11) unsigned @@ -4088,7 +4088,7 @@ defaultftpdatasent - bigint(20) unsigned + int(11) unsigned @@ -4498,7 +4498,7 @@ mask_and - bigint(20) unsigned + int(11) unsigned 0 @@ -4506,7 +4506,7 @@ mask_xor - bigint(20) unsigned + int(11) unsigned 0 @@ -6070,7 +6070,7 @@ status - bigint(20) unsigned + int(10) unsigned diff --git a/tests/Alchemy/Phrasea/SearchEngine/SearchEngineAbstractTest.php b/tests/Alchemy/Phrasea/SearchEngine/SearchEngineAbstractTest.php index 5154d8cdd6..38b7835b66 100644 --- a/tests/Alchemy/Phrasea/SearchEngine/SearchEngineAbstractTest.php +++ b/tests/Alchemy/Phrasea/SearchEngine/SearchEngineAbstractTest.php @@ -81,6 +81,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA $record = self::$DI['record_24']; $query_string = 'recordid=' . $record->get_record_id(); + self::$searchEngine->addRecord($record); + $this->updateIndex(); + self::$searchEngine->resetCache(); $results = self::$searchEngine->query($query_string, 0, 1); $this->assertEquals(1, $results->total()); @@ -96,6 +99,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA $record = self::$DI['record_24']; $query_string = 'storyid=' . $record->get_record_id(); + self::$searchEngine->addRecord($record); + $this->updateIndex(); + self::$searchEngine->resetCache(); $results = self::$searchEngine->query($query_string, 0, 1); $this->assertEquals(1, $results->total()); @@ -243,7 +249,8 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA $query_string = 'boomboklot' . $record->get_record_id() . 'onfield'; - $options->setFields(array($this->editRecord($query_string, $record))); + $field = $this->editRecord($query_string, $record); + $options->setFields(array($field)); self::$searchEngine->setOptions($options); diff --git a/tests/Alchemy/Phrasea/SearchEngine/SphinxSearchEngineTest.php b/tests/Alchemy/Phrasea/SearchEngine/SphinxSearchEngineTest.php index 27ed07de62..789d9ca985 100644 --- a/tests/Alchemy/Phrasea/SearchEngine/SphinxSearchEngineTest.php +++ b/tests/Alchemy/Phrasea/SearchEngine/SphinxSearchEngineTest.php @@ -20,7 +20,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest $app = new Application('test'); $appbox = $app['phraseanet.appbox']; - self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 9306, '127.0.0.1', 9308); + self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 19306, '127.0.0.1', 19308); self::$config = tempnam(sys_get_temp_dir(), 'tmp_sphinx.conf'); $configFile = self::$searchEngine->configurationPanel()->generateSphinxConf($appbox->get_databoxes(), self::$searchEngine->configurationPanel()->getConfiguration()); @@ -37,8 +37,15 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest self::$searchd = new Process($searchd . ' -c ' . self::$config); self::$searchd->run(); + + self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 19306, '127.0.0.1', 19308); + } + + public function tearDown() + { + self::$searchEngine->removeRecord(self::$DI['record_24']); - self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 9306, '127.0.0.1', 9308); + parent::tearDown(); } public function initialize()