• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Search/classes/Lucene/class.ilLuceneIndexer.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 // Todo check in settings which objects should be indexed
00048                 $this->__flushIndex();
00049                 $this->__indexFiles();
00050                 $this->__indexHTLMs();
00051 
00052                 return true;
00053         }
00054 
00055         // PRIVATE
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                         // Send files to lucene rpc server
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                         // Send files to lucene rpc server
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 ?>

Generated on Fri Dec 13 2013 10:18:31 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1