ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLuceneIndexer.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
36 {
37  function ilLuceneIndexer()
38  {
39  global $ilLog,$ilDB;
40 
41  $this->log =& $ilLog;
42  $this->db =& $ilDB;
43  }
44 
45  function index()
46  {
47  // Todo check in settings which objects should be indexed
48  $this->__flushIndex();
49  $this->__indexFiles();
50  $this->__indexHTLMs();
51 
52  return true;
53  }
54 
55  // PRIVATE
56  function __indexFiles()
57  {
58  include_once('Services/FileSystemStorage/classes/class.ilFileSystemStorage.php');
59 
60  global $tree;
61 
62  $query = "SELECT * FROM file_data ".
63  "WHERE file_type IN ('text/plain','application/pdf','text/html','text/x-pdf','application/x-pdf')";
64 
65  $res = $this->db->query($query);
66 
67  $counter = 0;
68  $files = array();
69  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
70  {
71  ++$counter;
72  $bname = ilUtil::getDataDir();
73  $bname .= ("/ilFiles/");
74  $bname .= ilFileSystemStorage::_createPathFromId($row->file_id,'file');
75  $vname = (sprintf("%03d", $row->version));
76 
77  if(is_file($bname.'/'.$vname.'/'.$row->file_name))
78  {
79  $files[$row->file_id] = $bname.'/'.$vname.'/'.$row->file_name;
80  }
81  else
82  {
83  $files[$row->file_id] = $bname.'/'.$row->file_name;
84  }
85  }
86  $this->log->write('Lucene indexer: Found '.$counter.' files for indexing');
87 
88  if(count($files))
89  {
90  // Send files to lucene rpc server
91  include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
92 
93  $rpc_adapter =& new ilLuceneRPCAdapter();
94  $rpc_adapter->setMode('file');
95  $rpc_adapter->setFiles($files);
96  if($rpc_adapter->send())
97  {
98  $this->log->write('Lucene indexer: files sent');
99  }
100  return true;
101  }
102  }
103  function __indexHTLMs()
104  {
105  global $ilias;
106 
107  $query = "SELECT * FROM object_data WHERE type = 'htlm'";
108  $res = $this->db->query($query);
109  $counter = 0;
110  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
111  {
112  ++$counter;
113  $lms[$row->obj_id] = ILIAS_ABSOLUTE_PATH.'/'.ILIAS_WEB_DIR.'/'.CLIENT_ID.'/lm_data/lm_'.$row->obj_id;
114 
115  }
116  $this->log->write('Lucene indexer: Found '.$counter.' html learning modules for indexing');
117 
118  if(count($lms))
119  {
120  // Send files to lucene rpc server
121  include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
122 
123  $rpc_adapter =& new ilLuceneRPCAdapter();
124  $rpc_adapter->setMode('htlm');
125  $rpc_adapter->setHTLMs($lms);
126  if($rpc_adapter->send())
127  {
128  $this->log->write('Lucene indexer: files sent');
129  }
130  return true;
131  }
132  }
133  function __flushIndex()
134  {
135  include_once './Services/Search/classes/Lucene/class.ilLuceneRPCAdapter.php';
136 
137  $rpc_adapter =& new ilLuceneRPCAdapter();
138  $rpc_adapter->setMode('flush');
139  if($rpc_adapter->send())
140  {
141  $this->log->write('Lucene indexer: deleted index');
142  }
143  return true;
144  }
145 }
146 ?>