wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.SearchIndexController.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.SearchIndexController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/application/controller/class.BatchController.php");
20 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/util/class.SearchUtil.php");
22 
23 /**
24  * @class SearchIndexController
25  * @ingroup Controller
26  * @brief SearchIndexController creates a Lucene index from the complete datastore.
27  *
28  * <b>Input actions:</b>
29  * - unspecified: Create the index
30  *
31  * <b>Output actions:</b>
32  * - none
33  *
34  * @author ingo herwig <ingo@wemove.com>
35  */
37 {
38 
39  /**
40  * @see BatchController::getWorkPackage()
41  */
42  function getWorkPackage($number)
43  {
44  if ($number == 0)
45  {
47  // get all types to index
48  $types = array();
49  $persistenceFacade = &PersistenceFacade::getInstance();
50  foreach (PersistenceFacade::getKnownTypes() as $type)
51  {
52  $tpl = &$persistenceFacade->create($type, BUILDDEPTH_SINGLE);
53  if ($tpl->isIndexInSearch()) {
54  array_push($types, $type);
55  }
56  }
58  return array('name' => Message::get('Collect objects'), 'size' => 1, 'oids' => $types, 'callback' => 'collect');
59  }
60  else {
61  // search is deactivated
62  return null;
63  }
64  }
65  else {
66  return null;
67  }
68  }
69  /**
70  * Collect all oids of the given types
71  * @param types The types to process
72  * @note This is a callback method called on a matching work package @see BatchController::addWorkPackage()
73  */
74  function collect($types)
75  {
76  $persistenceFacade = &PersistenceFacade::getInstance();
77  foreach ($types as $type)
78  {
79  $oids = $persistenceFacade->getOIDs($type);
80  if (sizeof($oids) == 0) {
81  $oids = array(1);
82  }
83  $this->addWorkPackage(Message::get('Indexing %1%', array($type)), 10, $oids, 'index');
84  }
85  }
86  /**
87  * Create the lucene index from the given objects
88  * @param oids The oids to process
89  * @note This is a callback method called on a matching work package @see BatchController::addWorkPackage()
90  */
91  function index($oids)
92  {
93  $persistenceFacade = &PersistenceFacade::getInstance();
94  foreach($oids as $oid)
95  {
97  {
98  $obj = &$persistenceFacade->load($oid, BUILDDEPTH_SINGLE);
100  }
101  }
102 
104  if ($this->getStepNumber() == $this->getNumberOfSteps() - 1) {
105  $this->addWorkPackage(Message::get('Optimizing index'), 1, array(0), 'optimize');
106  }
107  }
108 
109  function optimize($oids)
110  {
112  }
113  // PROTECTED REGION END
114 }
115 ?>
static optimizeIndex()
static commitIndex($optimize=true)
get($message, $parameters=null, $domain='', $lang='')
SearchIndexController creates a Lucene index from the complete datastore.
static isActivated()
static resetIndex()
addWorkPackage($name, $size, $oids, $callback, $args=null)
static indexInSearch(&$obj)
const BUILDDEPTH_SINGLE
BatchController allows to define work packages that will be processed in a sequence. It simplifies the usage of LongTaskController functionality for splitting different bigger tasks into many smaller (similar) tasks where the whole number of tasks isn't known at designtime.