[SearchEngine] Fix build on 32bit systems

This commit is contained in:
Romain Neutron
2012-10-23 11:34:01 +02:00
parent ac83a2f135
commit cf01631da7
10 changed files with 62 additions and 50 deletions

View File

@@ -15,7 +15,7 @@ before_script:
- tar xzf sphinx-2.0.6-release.tar.gz - 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" - 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 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;' - 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 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" - sudo mysql -e "GRANT ALL PRIVILEGES ON db_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION"

View File

@@ -340,8 +340,7 @@ class Manager
} }
break; break;
case AttributeInterface::NAME_STATUS: case AttributeInterface::NAME_STATUS:
$element->set_binary_status(decbin(bindec($element->get_status()) | bindec($attribute->getValue())));
$element->set_binary_status($element->get_status() | $attribute->getValue());
break; break;
case AttributeInterface::NAME_STORY: case AttributeInterface::NAME_STORY:

View File

@@ -489,8 +489,8 @@ searchd
# listen = 192.168.0.1:9312 # listen = 192.168.0.1:9312
# listen = 9312 # listen = 9312
# listen = /var/run/searchd.sock # listen = /var/run/searchd.sock
listen = 9306 listen = 127.0.0.1:19306
listen = 9308:mysql41 listen = 127.0.0.1:19308:mysql41
# log file, searchd run info is logged here # log file, searchd run info is logged here
# optional, default is \'searchd.log\' # optional, default is \'searchd.log\'

View File

@@ -117,7 +117,7 @@ class SphinxSearchEngine implements SearchEngineInterface
for ($i = 4; $i < 32; $i++) { for ($i = 4; $i < 32; $i++) {
if ($binStatus[$i]) { if ($binStatus[$i]) {
$status[] = crc32($record->get_databox()->get_sbas_id() . '_' . $i); $status[] = sprintf("%u", crc32($record->get_databox()->get_sbas_id() . '_' . $i));
} }
} }
@@ -131,8 +131,7 @@ class SphinxSearchEngine implements SearchEngineInterface
} }
foreach ($field->get_values() as $value) { foreach ($field->get_values() as $value) {
$this->rt_conn->exec("REPLACE INTO "
$sql = "REPLACE INTO "
. "metas_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES ( . "metas_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES (
'" . $value->getId() . "' '" . $value->getId() . "'
,'" . str_replace("'", "\'", $value->getValue()) . "' ,'" . str_replace("'", "\'", $value->getValue()) . "'
@@ -141,21 +140,19 @@ class SphinxSearchEngine implements SearchEngineInterface
," . $record->get_sbas_id() . " ," . $record->get_sbas_id() . "
," . $record->get_collection()->get_coll_id() . " ," . $record->get_collection()->get_coll_id() . "
," . (int) $record->is_grouping() . " ," . (int) $record->is_grouping() . "
," . crc32($record->get_sbas_id() . '_' . $value->getDatabox_field()->get_id()) . " ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $value->getDatabox_field()->get_id())) . "
," . crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id()) . " ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id())) . "
," . crc32($record->get_sbas_id() . '_' . $record->get_record_id()) . " ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_record_id())) . "
," . crc32($record->get_type()) . " ," . sprintf("%u", crc32($record->get_type())) . "
,0 ,0
," . (int) $value->getDatabox_field()->isBusiness() . " ," . (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') . " ," . $record->get_creation_date()->format('U') . "
,(" . implode(',', $status) . ") )"; ,(" . implode(',', $status) . ") )");
$this->rt_conn->exec($sql);
} }
} }
$this->rt_conn->exec("REPLACE INTO " $sql = "REPLACE INTO "
. "docs_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES ( . "docs_realtime" . $this->CRCdatabox($record->get_databox()) . " VALUES (
'" . $record->get_record_id() . "' '" . $record->get_record_id() . "'
,'" . str_replace("'", "\'", implode(' ', $all_datas)) . "' ,'" . str_replace("'", "\'", implode(' ', $all_datas)) . "'
@@ -163,12 +160,14 @@ class SphinxSearchEngine implements SearchEngineInterface
," . $record->get_sbas_id() . " ," . $record->get_sbas_id() . "
," . $record->get_collection()->get_coll_id() . " ," . $record->get_collection()->get_coll_id() . "
," . (int) $record->is_grouping() . " ," . (int) $record->is_grouping() . "
," . crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id()) . " ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_collection()->get_coll_id())) . "
," . crc32($record->get_sbas_id() . '_' . $record->get_record_id()) . " ," . sprintf("%u", crc32($record->get_sbas_id() . '_' . $record->get_record_id())) . "
," . crc32($record->get_type()) . " ," . sprintf("%u", crc32($record->get_type())) . "
,0 ,0
," . $record->get_creation_date()->format('U') . " ," . $record->get_creation_date()->format('U') . "
,(" . implode(',', $status) . ") )"); ,(" . implode(',', $status) . ") )";
$this->rt_conn->exec($sql);
return $this; return $this;
} }
@@ -388,13 +387,13 @@ class SphinxSearchEngine implements SearchEngineInterface
*/ */
public function CRCdatabox(\databox $databox) public function CRCdatabox(\databox $databox)
{ {
return crc32( return sprintf("%u", crc32(
str_replace( str_replace(
array('.', '%') array('.', '%')
, '_' , '_'
, sprintf('%s_%s_%s_%s', $databox->get_host(), $databox->get_port(), $databox->get_user(), $databox->get_dbname()) , 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(); $filters = array();
foreach ($options->collections() as $collection) { 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); $this->sphinx->SetFilter('crc_sbas_coll', $filters);
@@ -425,7 +424,7 @@ class SphinxSearchEngine implements SearchEngineInterface
$filters = array(); $filters = array();
foreach ($options->fields() as $field) { 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); $this->sphinx->SetFilter('crc_struct_id', $filters);
@@ -436,8 +435,8 @@ class SphinxSearchEngine implements SearchEngineInterface
$crc_coll_business = array(); $crc_coll_business = array();
foreach ($options->businessFieldsOn() as $collection) { foreach ($options->businessFieldsOn() as $collection) {
$crc_coll_business[] = crc32($collection->get_coll_id() . '_1'); $crc_coll_business[] = sprintf("%u", 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() . '_0'));
} }
$non_business = array(); $non_business = array();
@@ -452,7 +451,7 @@ class SphinxSearchEngine implements SearchEngineInterface
} }
foreach ($non_business as $collection) { 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); $this->sphinx->SetFilter('crc_coll_business', $crc_coll_business);
@@ -470,14 +469,14 @@ class SphinxSearchEngine implements SearchEngineInterface
continue; continue;
if (!array_key_exists($databox->get_sbas_id(), $status_opts[$n])) if (!array_key_exists($databox->get_sbas_id(), $status_opts[$n]))
continue; 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')); $this->sphinx->SetFilter('status', array($crc), ($status_opts[$n][$databox->get_sbas_id()] == '0'));
} }
} }
if ($options->getRecordType()) { if ($options->getRecordType()) {
$this->sphinx->SetFilter('crc_type', array(crc32($options->getRecordType()))); $this->sphinx->SetFilter('crc_type', array(sprintf("%u", crc32($options->getRecordType()))));
} }

View File

@@ -41,13 +41,13 @@ class module_console_sphinxGenerateSuggestion extends Command
$params = phrasea::sbas_params($this->container); $params = phrasea::sbas_params($this->container);
foreach ($params as $sbas_id => $p) { foreach ($params as $sbas_id => $p) {
$index = crc32( $index = sprintf("%u", crc32(
str_replace( str_replace(
array('.', '%') array('.', '%')
, '_' , '_'
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname']) , 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'; $tmp_file = $this->container['phraseanet.registry']->get('GV_RootPath') . 'tmp/dict' . $index . '.txt';

View File

@@ -137,7 +137,7 @@ class sphinx_configuration
foreach ($lb as $id => $params) { foreach ($lb as $id => $params) {
$serialized = str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])); $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 .= ' $conf .= '

View File

@@ -118,7 +118,7 @@
</field> </field>
<field> <field>
<name>server_coll_id</name> <name>server_coll_id</name>
<type>bigint(20)</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
<default>0</default> <default>0</default>
@@ -1076,7 +1076,7 @@
<fields> <fields>
<field> <field>
<name>id</name> <name>id</name>
<type>bigint(11) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra>auto_increment</extra> <extra>auto_increment</extra>
<default></default> <default></default>
@@ -1211,7 +1211,7 @@
</field> </field>
<field> <field>
<name>mask_and</name> <name>mask_and</name>
<type>bigint(20) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
@@ -1222,7 +1222,7 @@
<field> <field>
<name>mask_xor</name> <name>mask_xor</name>
<type>bigint(20) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
@@ -1903,7 +1903,7 @@
</field> </field>
<field> <field>
<name>sbas_id</name> <name>sbas_id</name>
<type>bigint(11) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
<default></default> <default></default>
@@ -1911,7 +1911,7 @@
</field> </field>
<field> <field>
<name>usr_id</name> <name>usr_id</name>
<type>bigint(11) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
<default></default> <default></default>
@@ -3541,7 +3541,7 @@
</field> </field>
<field> <field>
<name>ord</name> <name>ord</name>
<type>bigint(11) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
@@ -4088,7 +4088,7 @@
</field> </field>
<field> <field>
<name>defaultftpdatasent</name> <name>defaultftpdatasent</name>
<type>bigint(20) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
@@ -4498,7 +4498,7 @@
</field> </field>
<field> <field>
<name>mask_and</name> <name>mask_and</name>
<type>bigint(20) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
<default>0</default> <default>0</default>
@@ -4506,7 +4506,7 @@
</field> </field>
<field> <field>
<name>mask_xor</name> <name>mask_xor</name>
<type>bigint(20) unsigned</type> <type>int(11) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>
<default>0</default> <default>0</default>
@@ -6070,7 +6070,7 @@
<field> <field>
<name>status</name> <name>status</name>
<type>bigint(20) unsigned</type> <type>int(10) unsigned</type>
<null></null> <null></null>
<extra></extra> <extra></extra>

View File

@@ -81,6 +81,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
$record = self::$DI['record_24']; $record = self::$DI['record_24'];
$query_string = 'recordid=' . $record->get_record_id(); $query_string = 'recordid=' . $record->get_record_id();
self::$searchEngine->addRecord($record);
$this->updateIndex();
self::$searchEngine->resetCache(); self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1); $results = self::$searchEngine->query($query_string, 0, 1);
$this->assertEquals(1, $results->total()); $this->assertEquals(1, $results->total());
@@ -96,6 +99,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
$record = self::$DI['record_24']; $record = self::$DI['record_24'];
$query_string = 'storyid=' . $record->get_record_id(); $query_string = 'storyid=' . $record->get_record_id();
self::$searchEngine->addRecord($record);
$this->updateIndex();
self::$searchEngine->resetCache(); self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1); $results = self::$searchEngine->query($query_string, 0, 1);
$this->assertEquals(1, $results->total()); $this->assertEquals(1, $results->total());
@@ -243,7 +249,8 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
$query_string = 'boomboklot' . $record->get_record_id() . 'onfield'; $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); self::$searchEngine->setOptions($options);

View File

@@ -20,7 +20,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
$app = new Application('test'); $app = new Application('test');
$appbox = $app['phraseanet.appbox']; $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'); self::$config = tempnam(sys_get_temp_dir(), 'tmp_sphinx.conf');
$configFile = self::$searchEngine->configurationPanel()->generateSphinxConf($appbox->get_databoxes(), self::$searchEngine->configurationPanel()->getConfiguration()); $configFile = self::$searchEngine->configurationPanel()->generateSphinxConf($appbox->get_databoxes(), self::$searchEngine->configurationPanel()->getConfiguration());
@@ -38,7 +38,14 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
self::$searchd = new Process($searchd . ' -c ' . self::$config); self::$searchd = new Process($searchd . ' -c ' . self::$config);
self::$searchd->run(); self::$searchd->run();
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);
}
public function tearDown()
{
self::$searchEngine->removeRecord(self::$DI['record_24']);
parent::tearDown();
} }
public function initialize() public function initialize()