2011-07-21 07:11:39 +00:00
|
|
|
|
<?php
|
2018-10-29 09:50:02 +00:00
|
|
|
|
require_once("../inc/inc.ClassSettings.php");
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
|
|
|
|
echo "Usage:\n";
|
2013-02-14 10:27:51 +00:00
|
|
|
|
echo " seeddms-indexer [-h] [-v] [--config <file>]\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Description:\n";
|
2013-02-14 11:10:53 +00:00
|
|
|
|
echo " This program recreates the full text index of SeedDMS.\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Options:\n";
|
|
|
|
|
echo " -h, --help: print usage information and exit.\n";
|
|
|
|
|
echo " -v, --version: print version and exit.\n";
|
2015-06-26 14:17:02 +00:00
|
|
|
|
echo " -c: recreate index.\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo " --config: set alternative config file.\n";
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
2017-12-22 12:05:35 +00:00
|
|
|
|
$version = "0.0.2";
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$shortoptions = "hvc";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$longoptions = array('help', 'version', 'config:');
|
|
|
|
|
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print help and exit */
|
|
|
|
|
if(isset($options['h']) || isset($options['help'])) {
|
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print version and exit */
|
|
|
|
|
if(isset($options['v']) || isset($options['verѕion'])) {
|
|
|
|
|
echo $version."\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set alternative config file */
|
|
|
|
|
if(isset($options['config'])) {
|
|
|
|
|
$settings = new Settings($options['config']);
|
|
|
|
|
} else {
|
|
|
|
|
$settings = new Settings();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 14:17:02 +00:00
|
|
|
|
/* recreate index */
|
|
|
|
|
$recreate = false;
|
|
|
|
|
if(isset($options['c'])) {
|
|
|
|
|
$recreate = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 10:27:51 +00:00
|
|
|
|
if(isset($settings->_extraPath))
|
|
|
|
|
ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path'));
|
2018-10-29 09:50:02 +00:00
|
|
|
|
ini_set('include_path', $settings->_rootDir. PATH_SEPARATOR .ini_get('include_path'));
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2018-10-29 09:50:02 +00:00
|
|
|
|
include("../inc/inc.Extension.php");
|
2013-02-14 11:10:53 +00:00
|
|
|
|
require_once("SeedDMS/Core.php");
|
2015-08-10 19:43:15 +00:00
|
|
|
|
if($settings->_fullSearchEngine == 'sqlitefts') {
|
|
|
|
|
$indexconf = array(
|
|
|
|
|
'Indexer' => 'SeedDMS_SQLiteFTS_Indexer',
|
|
|
|
|
'Search' => 'SeedDMS_SQLiteFTS_Search',
|
|
|
|
|
'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument'
|
|
|
|
|
);
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2015-08-10 19:43:15 +00:00
|
|
|
|
require_once('SeedDMS/SQLiteFTS.php');
|
|
|
|
|
} else {
|
|
|
|
|
$indexconf = array(
|
|
|
|
|
'Indexer' => 'SeedDMS_Lucene_Indexer',
|
|
|
|
|
'Search' => 'SeedDMS_Lucene_Search',
|
|
|
|
|
'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
require_once('SeedDMS/Lucene.php');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */
|
2015-06-26 14:17:02 +00:00
|
|
|
|
global $settings;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo $indent."D ".$folder->getName()."\n";
|
|
|
|
|
$subfolders = $folder->getSubFolders();
|
|
|
|
|
foreach($subfolders as $subfolder) {
|
2015-08-10 19:43:15 +00:00
|
|
|
|
tree($dms, $index, $indexconf, $subfolder, $indent.' ');
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
$documents = $folder->getDocuments();
|
|
|
|
|
foreach($documents as $document) {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
echo $indent." ".$document->getId().":".$document->getName()." ";
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$lucenesearch = new $indexconf['Search']($index);
|
|
|
|
|
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
|
|
|
|
|
try {
|
2017-12-22 12:05:35 +00:00
|
|
|
|
$idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout);
|
2018-11-13 07:47:46 +00:00
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $document, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$index->addDocument($idoc);
|
2015-08-10 19:43:15 +00:00
|
|
|
|
echo " (Document added)\n";
|
|
|
|
|
} catch(Exception $e) {
|
|
|
|
|
echo " (Timeout)\n";
|
|
|
|
|
}
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
try {
|
|
|
|
|
$created = (int) $hit->getDocument()->getFieldValue('created');
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} catch (Exception $e) {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$created = 0;
|
|
|
|
|
}
|
|
|
|
|
$content = $document->getLatestContent();
|
2019-01-08 15:59:55 +00:00
|
|
|
|
if($created > $content->getDate()) {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
echo " (Document unchanged)\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
2016-04-05 15:03:03 +00:00
|
|
|
|
$index->delete($hit->id);
|
|
|
|
|
try {
|
2018-11-13 07:47:46 +00:00
|
|
|
|
$idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout);
|
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $document, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$index->addDocument($idoc);
|
2016-04-05 15:03:03 +00:00
|
|
|
|
echo " (Document updated)\n";
|
|
|
|
|
} catch(Exception $e) {
|
|
|
|
|
echo " (Timeout)\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} /* }}} */
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
|
2013-06-06 12:41:55 +00:00
|
|
|
|
if(!$dms->checkVersion()) {
|
2015-08-10 19:43:15 +00:00
|
|
|
|
echo "Database update needed.\n";
|
|
|
|
|
exit(1);
|
2013-06-06 12:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$dms->setRootFolderID($settings->_rootFolderID);
|
|
|
|
|
|
2015-06-26 14:17:02 +00:00
|
|
|
|
if($recreate)
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$index = $indexconf['Indexer']::create($settings->_luceneDir);
|
2015-06-26 14:17:02 +00:00
|
|
|
|
else
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$index = $indexconf['Indexer']::open($settings->_luceneDir);
|
|
|
|
|
if(!$index) {
|
|
|
|
|
echo "Could not create index.\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$indexconf['Indexer']::init($settings->_stopWordsFile);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$folder = $dms->getFolder($settings->_rootFolderID);
|
2015-08-10 19:43:15 +00:00
|
|
|
|
tree($dms, $index, $indexconf, $folder);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$index->commit();
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$index->optimize();
|
2011-07-21 07:11:39 +00:00
|
|
|
|
?>
|