ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRepositoryObjectDetailSearch.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Search/classes/class.ilSearchSettings.php';
5 
18 {
19  protected $settings = null;
20 
21  protected $obj_id;
22  protected $type;
23  protected $query_string;
24 
28  public function __construct($a_obj_id)
29  {
30  $this->obj_id = $a_obj_id;
31  $this->type = ilObject::_lookupType($this->getObjId());
32 
34  }
35 
40  public function getSettings()
41  {
42  return $this->settings;
43  }
44 
49  public function getObjId()
50  {
51  return $this->obj_id;
52  }
53 
54  public function getType()
55  {
56  return $this->type;
57  }
58 
59 
60  public function setQueryString($a_query)
61  {
62  $this->query_string = $a_query;
63  }
64 
65 
69  public function getQueryString()
70  {
71  return $this->query_string;
72  }
73 
80  public function performSearch()
81  {
82  if ($this->getSettings()->enabledLucene()) {
83  return $this->performLuceneSearch();
84  } else {
85  return $this->performDBSearch();
86  }
87  }
88 
93  protected function performLuceneSearch()
94  {
95  include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
96  try {
97  $qp = new ilLuceneQueryParser($this->getQueryString());
98  $qp->parse();
99  } catch (ilLuceneQueryParserException $e) {
100  ilLoggerFactory::getLogger('src')->warning('Invalid query: ' . $e->getMessage());
101  throw $e;
102  }
103 
104  include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
105  $searcher = ilLuceneSearcher::getInstance($qp);
106  $searcher->highlight(array($this->getObjId()));
107 
108  include_once './Services/Search/classes/class.ilRepositoryObjectDetailSearchResult.php';
109  $detail_search_result = new ilRepositoryObjectDetailSearchResult();
110 
111  if ($searcher->getHighlighter() instanceof ilLuceneHighlighterResultParser) {
112  foreach ($searcher->getHighlighter()->getSubItemIds($this->getObjId()) as $sub_id) {
113  $detail_search_result->addResultSet(
114  array(
115  'obj_id' => $this->getObjId(),
116  'item_id' => $sub_id,
117  'relevance' => $searcher->getHighlighter()->getRelevance($this->getObjId(), $sub_id),
118  'content' => $searcher->getHighlighter()->getContent($this->getObjId(), $sub_id)
119  )
120  );
121  }
122  }
123  return $detail_search_result;
124  }
125 
126 
131  protected function performDBSearch()
132  {
133  // query parser
134  include_once 'Services/Search/classes/class.ilQueryParser.php';
135 
136  $query_parser = new ilQueryParser($this->getQueryString());
137 
138  $query_parser->setCombination(
139  ($this->getSettings()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND) ?
142  );
143  $query_parser->parse();
144 
145  if (!$query_parser->validate()) {
146  throw new Exception($query_parser->getMessage());
147  }
148  include_once 'Services/Search/classes/class.ilSearchResult.php';
149  $search_result = new ilSearchResult();
150 
151  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
152  $search = ilObjectSearchFactory::getByTypeSearchInstance($this->getType(), $query_parser);
153 
154  switch ($this->getType()) {
155  case 'wiki':
156  $search->setFilter(array('wpg'));
157  break;
158  }
159 
160  $search->setIdFilter(array($this->getObjId()));
161 
162  $search_result->mergeEntries($search->performSearch());
163 
164  include_once './Services/Search/classes/class.ilRepositoryObjectDetailSearchResult.php';
165  $detail_search_result = new ilRepositoryObjectDetailSearchResult();
166 
167  foreach ($search_result->getEntries() as $entry) {
168  foreach ((array) $entry['child'] as $child) {
169  $detail_search_result->addResultSet(
170  array(
171  'obj_id' => $entry['obj_id'],
172  'item_id' => $child
173  )
174  );
175  }
176  }
177  return $detail_search_result;
178  }
179 }
Parses result XML from lucene search highlight.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
const QP_COMBINATION_OR
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getByTypeSearchInstance($a_object_type, $a_query_parser)
settings()
Definition: settings.php:2
static getLogger($a_component_id)
Get component logger.
const QP_COMBINATION_AND