Olegpro\BitrixSphinx
, (*1)
ΠΠ°ΠΊΠ΅Ρ Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅Ρ Π² 1Π‘-ΠΠΈΡΡΠΈΠΊΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΡΠ°Π±ΠΎΡΠ°ΡΡ Ρ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΠΌΠΈ sphinx, ΡΠ΅ΡΠ΅Π· ORM D7, ΠΊΠ°ΠΊ Ρ ΠΏΡΠΈΠ²ΡΡΠ½ΡΠΌΠΈ ΡΡΡΠ½ΠΎΡΡΡΠΌΠΈ (Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ \Bitrix\Iblock\ElementTable ΠΈΠ»ΠΈ \Bitrix\Catalog\PriceTable), (*2)
ΠΠ°ΡΡΡΠΎΠΉΠΊΠ°
Π‘ΠΎΠ·Π΄Π°ΡΠΌ ΠΊΠ»Π°ΡΡ ORM-ΡΡΡΠ½ΠΎΡΡΡ:, (*3)
<?php
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Olegpro\BitrixSphinx\Entity\SphinxDataManager;
use Olegpro\BitrixSphinx\Entity\SphinxQuery;
Loc::loadMessages(__FILE__);
class SampleTable extends SphinxDataManager
{
/**
* Returns index sphinx name for entity.
*
* @return string
*/
public static function getTableName()
{
return 'sample_index';
}
/**
* Returns sphinx-connection name for entity
*
* @return string
*/
public static function getConnectionName()
{
return 'sphinx';
}
/**
* Creates and returns the Query object for the entity
*
* @return SphinxQuery
*/
public static function query()
{
return new SphinxQuery(static::getEntity());
}
/**
* Returns entity map definition.
*
* @return array
*/
public static function getMap()
{
return [
new Main\Entity\IntegerField('id', [
'primary' => true,
]),
new Main\Entity\StringField('name'),
new Main\Entity\BooleanField('available', [
'values' => [0, 1],
])
];
}
}
ΠΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π½ΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π² ΡΠ°ΠΉΠ»Π΅ /bitrix/.settings.php Π² ΡΠ΅ΠΊΡΠΈΡ connections:, (*4)
'connections' =>
array(
'value' =>
array(
'default' =>
array(
// ...
)
),
'sphinx' =>
array(
'className' => '\\Olegpro\\BitrixSphinx\\DB\\SphinxConnection',
'host' => '127.0.0.1:9306',
'database' => '',
'login' => '',
'password' => '',
'options' => 1,
),
),
'readonly' => true,
),
ΠΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅
<?php
use Bitrix\Main\Application;
use Bitrix\Main\Entity\ExpressionFieldd;
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/header.php');
Application::getConnection(SampleTable::getConnectionName())->startTracker(true);
$iterator = SampleTable::getList([
'select' => [
'*',
new ExpressionField('weight', 'WEIGHT()', 'id'),
],
'match' => 'ΠΊΠ½ΠΈΠ³Π°',
'filter' => [
'=available' => 1,
],
'limit' => 10,
'order' => [
'weight' => 'DESC',
],
'option' => [
'max_matches' => 50000,
],
]);
echo '
';print_r($iterator->getTrackerQuery()->getSql());echo '
';
echo '
';print_r($iterator->fetchAll());echo '
';
Π‘ ΠΏΠΎΡΡΡΠ°Π½ΠΈΡΠ½ΠΎΠΉ Π½Π°Π²ΠΈΠ³Π°ΡΠΈΠ΅ΠΉ
<?php
use Bitrix\Main\Application;
use Bitrix\Main\Entity\ExpressionFieldd;
use Bitrix\Main\UI\PageNavigation;
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/header.php');
Application::getConnection(SampleTable::getConnectionName())->startTracker(true);
$nav = new PageNavigation('s');
$nav->allowAllRecords(false)
->setPageSize(10)
->initFromUri();
$iterator = SampleTable::getList([
'select' => [
'*',
new ExpressionField('weight', 'WEIGHT()', 'id'),
],
'match' => 'ΠΊΠ½ΠΈΠ³Π°',
'filter' => [
'=available' => 1,
],
'count_total' => true,
'offset' => $nav->getOffset(),
'limit' => $nav->getLimit(),
'order' => [
'weight' => 'DESC',
],
'option' => [
'max_matches' => 50000,
],
]);
$nav->setRecordCount($iterator->getCount());
echo '
';print_r($iterator->getTrackerQuery()->getSql());echo '
';
echo '
';print_r($iterator->fetchAll());echo '
';
$APPLICATION->IncludeComponent(
"bitrix:main.pagenavigation",
"",
array(
"NAV_OBJECT" => $nav,
"SEF_MODE" => "N",
),
false
);
ΠΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠΎΠ»ΡΠΊΠΎ Ρ master-ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ΠΌ
ΠΠΎΠΆΠ½ΠΎ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ Π³Π»ΠΎΠ±Π°Π»ΡΠ½ΠΎ Π΄Π»Ρ Π²ΡΠ΅Π³ΠΎ ΡΠ°ΠΉΡΠ°, Π΄ΠΎΠ±Π°Π²ΠΈΠ² Π² /bitrix/.settings.php, (*5)
'olegpro_bitrix_sphinx' =>
array (
'value' =>
array (
'use_connection_master_only' => true,
),
'readonly' => false,
),
ΠΠΎΠΆΠ½ΠΎ ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π·Π°ΠΏΡΠΎΡΠ° ΠΏΠ΅ΡΠ΅Π΄Π°Π² use_connection_master_only = true:, (*6)
$iterator = SampleTable::getList([
'select' => [
'*',
new ExpressionField('weight', 'WEIGHT()', 'id'),
],
'match' => 'ΠΊΠ½ΠΈΠ³Π°',
'filter' => [
'=available' => 1,
],
'limit' => 10,
'order' => [
'weight' => 'DESC',
],
'option' => [
'max_matches' => 50000,
],
'use_connection_master_only' => true,
]);
Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΠΏΠ°ΠΊΠ΅ΡΠ°
ΠΠΎΠ±Π°Π²ΠΈΡΡ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΡ Π² Composer:, (*7)
composer require olegpro/bitrix-sphinx