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 global $tree;
00059
00060 $query = "SELECT * FROM file_data ".
00061 "WHERE file_type IN ('text/plain','application/pdf','text/html')";
00062
00063 $res = $this->db->query($query);
00064
00065 $counter = 0;
00066 $files = array();
00067 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00068 {
00069 ++$counter;
00070 $bname = ilUtil::getDataDir();
00071 $bname .= ("/files/file_".$row->file_id);
00072 $vname = (sprintf("%03d", $row->version));
00073
00074 if(is_file($bname.'/'.$vname.'/'.$row->file_name))
00075 {
00076 $files[$row->file_id] = $bname.'/'.$vname.'/'.$row->file_name;
00077 }
00078 else
00079 {
00080 $files[$row->file_id] = $bname.'/'.$row->file_name;
00081 }
00082 }
00083 $this->log->write('Lucene indexer: Found '.$counter.' files for indexing');
00084
00085 if(count($files))
00086 {
00087
00088 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00089
00090 $rpc_adapter =& new ilLuceneRPCAdapter();
00091 $rpc_adapter->setMode('file');
00092 $rpc_adapter->setFiles($files);
00093 if($rpc_adapter->send())
00094 {
00095 $this->log->write('Lucene indexer: files sent');
00096 }
00097 return true;
00098 }
00099 }
00100 function __indexHTLMs()
00101 {
00102 global $ilias;
00103
00104 $query = "SELECT * FROM object_data WHERE type = 'htlm'";
00105 $res = $this->db->query($query);
00106 $counter = 0;
00107 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00108 {
00109 ++$counter;
00110 $lms[$row->obj_id] = ILIAS_ABSOLUTE_PATH.'/'.ILIAS_WEB_DIR.'/'.CLIENT_ID.'/lm_data/lm_'.$row->obj_id;
00111
00112 }
00113 $this->log->write('Lucene indexer: Found '.$counter.' html learning modules for indexing');
00114
00115 if(count($lms))
00116 {
00117
00118 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00119
00120 $rpc_adapter =& new ilLuceneRPCAdapter();
00121 $rpc_adapter->setMode('htlm');
00122 $rpc_adapter->setHTLMs($lms);
00123 if($rpc_adapter->send())
00124 {
00125 $this->log->write('Lucene indexer: files sent');
00126 }
00127 return true;
00128 }
00129 }
00130 function __flushIndex()
00131 {
00132 include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
00133
00134 $rpc_adapter =& new ilLuceneRPCAdapter();
00135 $rpc_adapter->setMode('flush');
00136 if($rpc_adapter->send())
00137 {
00138 $this->log->write('Lucene indexer: deleted index');
00139 }
00140 return true;
00141 }
00142 }
00143 ?>