ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_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
33 $this->settings = ilSearchSettings::getInstance();
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 {
72 }
73
80 public function performSearch()
81 {
82 if($this->getSettings()->enabledLucene())
83 {
84 return $this->performLuceneSearch();
85 }
86 else
87 {
88 return $this->performDBSearch();
89 }
90 }
91
96 protected function performLuceneSearch()
97 {
98 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
99 try
100 {
101 $qp = new ilLuceneQueryParser($this->getQueryString());
102 $qp->parse();
103 }
105 {
106 ilLoggerFactory::getLogger('src')->warning('Invalid query: ' . $e->getMessage());
107 throw $e;
108 }
109
110 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
111 $searcher = ilLuceneSearcher::getInstance($qp);
112 $searcher->highlight(array($this->getObjId()));
113
114 include_once './Services/Search/classes/class.ilRepositoryObjectDetailSearchResult.php';
115 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
116
117 if($searcher->getHighlighter() instanceof ilLuceneHighlighterResultParser)
118 {
119 foreach($searcher->getHighlighter()->getSubItemIds($this->getObjId()) as $sub_id)
120 {
121 $detail_search_result->addResultSet(
122 array(
123 'obj_id' => $this->getObjId(),
124 'item_id' => $sub_id,
125 'relevance' => $searcher->getHighlighter()->getRelevance($this->getObjId(),$sub_id),
126 'content' => $searcher->getHighlighter()->getContent($this->getObjId(),$sub_id)
127 )
128 );
129 }
130 }
131 return $detail_search_result;
132 }
133
134
139 protected function performDBSearch()
140 {
141 // query parser
142 include_once 'Services/Search/classes/class.ilQueryParser.php';
143
144 $query_parser = new ilQueryParser($this->getQueryString());
145
146 $query_parser->setCombination(
147 ($this->getSettings()->getDefaultOperator() == ilSearchSettings::OPERATOR_AND) ?
150 );
151 $query_parser->parse();
152
153 if(!$query_parser->validate())
154 {
155 throw new Exception($query_parser->getMessage());
156 }
157 include_once 'Services/Search/classes/class.ilSearchResult.php';
158 $search_result = new ilSearchResult();
159
160 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
161 $search = ilObjectSearchFactory::getByTypeSearchInstance($this->getType(), $query_parser);
162
163 switch($this->getType())
164 {
165 case 'wiki':
166 $search->setFilter(array('wpg'));
167 break;
168 }
169
170 $search->setIdFilter(array($this->getObjId()));
171
172 $search_result->mergeEntries($search->performSearch());
173
174 include_once './Services/Search/classes/class.ilRepositoryObjectDetailSearchResult.php';
175 $detail_search_result = new ilRepositoryObjectDetailSearchResult();
176
177 foreach($search_result->getEntries() as $entry)
178 {
179 foreach((array) $entry['child'] as $child)
180 {
181 $detail_search_result->addResultSet(
182 array(
183 'obj_id' => $entry['obj_id'],
184 'item_id' => $child
185 )
186 );
187 }
188 }
189 return $detail_search_result;
190 }
191}
192?>
const QP_COMBINATION_OR
const QP_COMBINATION_AND
static getLogger($a_component_id)
Get component logger.
Parses result XML from lucene search highlight.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static getByTypeSearchInstance($a_object_type, $a_query_parser)
static _lookupType($a_id, $a_reference=false)
lookup object type