Answer the question
In order to leave comments, you need to log in
How to solve the problem with duplicate id in sphinx?
There is a parser that works in two threads and records are added to the database then to the sphinx
There is an rt index when a new record is made to the database, to add to the sphinx I do this,
$flow - This is the parsing stream
$maxId = (new Query())->select('id')->from(Yii::$app->params['real_index'])->max('id');
if((($maxId % 2) == 0 && $flow == 1) || (($maxId % 2) != 0 && $flow == 2)){
$id = $maxId + 1;
} elseif((($maxId % 2) == 0 && $flow == 2) || (($maxId % 2) != 0 && $flow == 1)) {
$id = $maxId + 2;
} else {
$id = $maxId + 1;
}
Yii::$app->sphinx->createCommand(
'INSERT INTO `'.Yii::$app->params['real_index'].'` (`id`, `product_id`, `product_name`, `description`, `company_id`) VALUES (:id, :product_id, :product_name, :description, :company_id)',
[
'id' => $id,
'product_id' => (string)$model->_id,
'product_name' => $model->product_name,
'description' => $model->description ? str_replace('\'', '', $model->description) : '',
'company_id' => isset($model->company_id) ? $model->company_id : '',
]
)->execute();
Answer the question
In order to leave comments, you need to log in
if you have two single-threaded parsers, then even or even parsers should solve your problem, just debug the code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question