• Main Page
  • Related Pages
  • Modules
  • 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                 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                         // Send files to lucene rpc server
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                         // Send files to lucene rpc server
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 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1