Skip to content
Snippets Groups Projects
Verified Commit 3ccfabc6 authored by Damien's avatar Damien
Browse files

FEAT #10525 TIME 0:30 Optimize + delete index

parent 2bde167e
No related branches found
No related tags found
No related merge requests found
......@@ -25,20 +25,26 @@ abstract class AttachmentModelAbstract
ValidatorModel::notEmpty($aArgs, ['select']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($aArgs, ['limit']);
ValidatorModel::boolType($aArgs, ['isVersion']);
if (!empty($aArgs['isVersion'])) {
$table = 'res_version_attachments';
} else {
$table = 'res_attachments';
}
$aResources = DatabaseModel::select([
$attachments = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => empty($aArgs['table']) ? ['res_attachments'] : $aArgs['table'],
'table' => [$table],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'],
'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit']
]);
return $aResources;
return $attachments;
}
public static function getOnView(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['select']);
......
......@@ -82,6 +82,12 @@ class FullTextController
\Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
$index->setMaxBufferedDocs(1000);
$term = new \Zend_Search_Lucene_Index_Term((integer)$args['resId'], 'Id');
$terms = $index->termDocs($term);
foreach ($terms as $value) {
$index->delete($value);
}
$doc = new \Zend_Search_Lucene_Document();
$doc->addField(\Zend_Search_Lucene_Field::UnIndexed('Id', (integer)$args['resId']));
......@@ -89,7 +95,9 @@ class FullTextController
$index->addDocument($doc);
$index->commit();
$index->optimize();
if ((integer)$args['resId'] % 100 === 0) {
$index->optimize(); // Optimize every 100 documents
}
} catch (\Exception $e) {
return ['errors' => 'Full Text index failed : ' . $e];
}
......@@ -148,9 +156,9 @@ class FullTextController
} else {
$resIds = AttachmentModel::get([
'select' => ['res_id'],
'table' => [$args['collId'] == 'attachments_coll' ? 'res_attachments' : 'res_version_attachments'],
'isVersion' => $args['collId'] == 'attachments_version_coll',
'where' => ['attachment_type <> ?', 'status NOT IN (?)', 'fulltext_result = ?'],
'data' => ['print_folder', ['DEL','OBS','TMP'],'ERROR'],
'data' => ['print_folder', ['DEL','OBS','TMP'], 'ERROR'],
]);
}
return $resIds;
......
......@@ -42,7 +42,6 @@ class FullTextScript
{
$customId = '';
$resId = '';
$userId = '';
$collId = '';
$mode = '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment