Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 class ilLuceneIndexer
00036 {
00037 function ilLuceneIndexer()
00038 {
00039 global $ilLog,$ilDB;
00040
00041 $this->log =& $ilLog;
00042 $this->db =& $ilDB;
00043 }
00044
00045 function index()
00046 {
00047
00048 $this->__flushIndex();
00049 $this->__indexFiles();
00050 $this->__indexHTLMs();
00051
00052 return true;
00053 }
00054
00055
00056 function __indexFiles()
00057 {
00058 include_once('Services/FileSystemStorage/classes/class.ilFileSystemStorage.php');
00059
00060 global $tree;
00061
00062 $query = "SELECT * FROM file_data ".
00063 "WHERE file_type IN ('text/plain','application/pdf','text/html','text/x-pdf','application/x-pdf')";
00064
00065 $res = $this->db->query($query);
00066
00067 $counter = 0;
00068 $files = array();
00069 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00070 {
00071 ++$counter;
00072 $bname = ilUtil::getDataDir();
00073 $bname .= ("/ilFiles/");
00074 $bname .= ilFileSystemStorage::_createPathFromId($row->file_id,'file');
00075 $vname = (sprintf("%03d", $row->version));
00076
00077 if(is_file($bname.'/'.$vname.'/'.$row->file_name))
00078 {
00079 $files[$row->file_id] = $bname.'/'.$vname.'/'.$row->file_name;
00080 }
00081 else
00082 {
00083 $files[$row->file_id] = $bname.'/'.$row->file_name;
00084 }
00085 }
00086 $this->log->write('Lucene indexer: Found '.$counter.' files for indexing');
00087
00088 if(count($files))
00089 {
00090
00091 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00092
00093 $rpc_adapter =& new ilLuceneRPCAdapter();
00094 $rpc_adapter->setMode('file');
00095 $rpc_adapter->setFiles($files);
00096 if($rpc_adapter->send())
00097 {
00098 $this->log->write('Lucene indexer: files sent');
00099 }
00100 return true;
00101 }
00102 }
00103 function __indexHTLMs()
00104 {
00105 global $ilias;
00106
00107 $query = "SELECT * FROM object_data WHERE type = 'htlm'";
00108 $res = $this->db->query($query);
00109 $counter = 0;
00110 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00111 {
00112 ++$counter;
00113 $lms[$row->obj_id] = ILIAS_ABSOLUTE_PATH.'/'.ILIAS_WEB_DIR.'/'.CLIENT_ID.'/lm_data/lm_'.$row->obj_id;
00114
00115 }
00116 $this->log->write('Lucene indexer: Found '.$counter.' html learning modules for indexing');
00117
00118 if(count($lms))
00119 {
00120
00121 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00122
00123 $rpc_adapter =& new ilLuceneRPCAdapter();
00124 $rpc_adapter->setMode('htlm');
00125 $rpc_adapter->setHTLMs($lms);
00126 if($rpc_adapter->send())
00127 {
00128 $this->log->write('Lucene indexer: files sent');
00129 }
00130 return true;
00131 }
00132 }
00133 function __flushIndex()
00134 {
00135 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00136
00137 $rpc_adapter =& new ilLuceneRPCAdapter();
00138 $rpc_adapter->setMode('flush');
00139 if($rpc_adapter->send())
00140 {
00141 $this->log->write('Lucene indexer: deleted index');
00142 }
00143 return true;
00144 }
00145 }
00146 ?>