put fulltext index into service

This commit is contained in:
Uwe Steinmann 2020-09-08 17:06:26 +02:00
parent 73b957281f
commit 3a183a452a
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,84 @@
<?php
/**
* Implementation of fulltext service
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2016 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Implementation of fulltext service
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2016 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_FulltextService {
/**
* List of services for searching fulltext
*/
protected $services;
/**
* List of converters
*/
protected $converters;
/**
* Max file size for imediate indexing
*/
protected $maxsize;
public function __construct() {
$this->services = array();
$this->converters = array();
$this->maxsize = 0;
$this->indexdir = '';
$this->index = null;
}
public function addService($name, $service) {
$this->services[$name] = $service;
}
public function setConverters($converters) {
$this->converters = $converters;
}
public function setMaxSize($maxsize) {
$this->maxsize = $maxsize;
}
public function setIndexDir($indexdir) {
$this->indexdir = $indexdir;
}
public function IndexedDocument($document) {
$indexcontent = $document->getLatestContent()->getFileSize() < $this->maxsize;
return new $this->services[0]['IndexedDocument']($document->getDMS(), $document, $this->converters, $indexcontent);
}
public function Indexer($recreate) {
if($this->indexdir) {
if($recreate)
$this->index = $this->services[0]['Indexer']::create($this->indexdir);
else
$this->index = $this->services[0]['Indexer']::open($this->indexdir);
return $this->index;
} else
return null;
}
public function Indexer($recreate) {
return new $this->services[0]['Search']();
}
}

View File

@ -52,6 +52,9 @@ if (get_magic_quotes_gpc()) {
unset($process); unset($process);
} }
require_once("inc.ClassFulltextService.php");
$fulltextservice = new SeedDMS_FulltextService();
$indexconf = null; $indexconf = null;
if($settings->_enableFullSearch) { if($settings->_enableFullSearch) {
if($settings->_fullSearchEngine == 'sqlitefts') { if($settings->_fullSearchEngine == 'sqlitefts') {
@ -60,6 +63,7 @@ if($settings->_enableFullSearch) {
'Search' => 'SeedDMS_SQLiteFTS_Search', 'Search' => 'SeedDMS_SQLiteFTS_Search',
'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument' 'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument'
); );
$fulltextservice->addService('sqlitefts', $indexconf);
require_once('SeedDMS/SQLiteFTS.php'); require_once('SeedDMS/SQLiteFTS.php');
} else { } else {
@ -68,12 +72,15 @@ if($settings->_enableFullSearch) {
'Search' => 'SeedDMS_Lucene_Search', 'Search' => 'SeedDMS_Lucene_Search',
'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument' 'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument'
); );
$fulltextservice->addService('lucene', $indexconf);
if(!empty($settings->_luceneClassDir)) if(!empty($settings->_luceneClassDir))
require_once($settings->_luceneClassDir.'/Lucene.php'); require_once($settings->_luceneClassDir.'/Lucene.php');
else else
require_once('SeedDMS/Lucene.php'); require_once('SeedDMS/Lucene.php');
} }
$fulltextservice->setConverters(isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null);
$fulltextservice->setMaxSize($settings->_maxSizeForFullText);
} }
$settings->_indexconf = $indexconf; $settings->_indexconf = $indexconf;