|
@@ 123-176 (lines=54) @@
|
| 120 |
|
* |
| 121 |
|
* @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
| 122 |
|
*/ |
| 123 |
|
public function findContent(Query $query, array $languageFilter = array()) |
| 124 |
|
{ |
| 125 |
|
if (!isset($languageFilter['languages'])) { |
| 126 |
|
$languageFilter['languages'] = array(); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
if (!isset($languageFilter['useAlwaysAvailable'])) { |
| 130 |
|
$languageFilter['useAlwaysAvailable'] = true; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
$start = microtime(true); |
| 134 |
|
$query->filter = $query->filter ?: new Criterion\MatchAll(); |
| 135 |
|
$query->query = $query->query ?: new Criterion\MatchAll(); |
| 136 |
|
|
| 137 |
|
if (count($query->facetBuilders)) { |
| 138 |
|
throw new NotImplementedException('Facets are not supported by the legacy search engine.'); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
// The legacy search does not know about scores, so that we just |
| 142 |
|
// combine the query with the filter |
| 143 |
|
$filter = new Criterion\LogicalAnd(array($query->query, $query->filter)); |
| 144 |
|
|
| 145 |
|
$data = $this->gateway->find( |
| 146 |
|
$filter, |
| 147 |
|
$query->offset, |
| 148 |
|
$query->limit, |
| 149 |
|
$query->sortClauses, |
| 150 |
|
$languageFilter, |
| 151 |
|
$query->performCount |
| 152 |
|
); |
| 153 |
|
|
| 154 |
|
$result = new SearchResult(); |
| 155 |
|
$result->time = microtime(true) - $start; |
| 156 |
|
$result->totalCount = $data['count']; |
| 157 |
|
$contentInfoList = $this->contentMapper->extractContentInfoFromRows( |
| 158 |
|
$data['rows'], |
| 159 |
|
'', |
| 160 |
|
'main_tree_' |
| 161 |
|
); |
| 162 |
|
|
| 163 |
|
foreach ($contentInfoList as $index => $contentInfo) { |
| 164 |
|
$searchHit = new SearchHit(); |
| 165 |
|
$searchHit->valueObject = $contentInfo; |
| 166 |
|
$searchHit->matchedTranslation = $this->extractMatchedLanguage( |
| 167 |
|
$data['rows'][$index]['language_mask'], |
| 168 |
|
$data['rows'][$index]['initial_language_id'], |
| 169 |
|
$languageFilter |
| 170 |
|
); |
| 171 |
|
|
| 172 |
|
$result->searchHits[] = $searchHit; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
return $result; |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
protected function extractMatchedLanguage($languageMask, $mainLanguageId, $languageSettings) |
| 179 |
|
{ |
|
@@ 241-288 (lines=48) @@
|
| 238 |
|
/** |
| 239 |
|
* @see \eZ\Publish\SPI\Search\Handler::findLocations |
| 240 |
|
*/ |
| 241 |
|
public function findLocations(LocationQuery $query, array $languageFilter = array()) |
| 242 |
|
{ |
| 243 |
|
if (!isset($languageFilter['languages'])) { |
| 244 |
|
$languageFilter['languages'] = array(); |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
if (!isset($languageFilter['useAlwaysAvailable'])) { |
| 248 |
|
$languageFilter['useAlwaysAvailable'] = true; |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
$start = microtime(true); |
| 252 |
|
$query->filter = $query->filter ?: new Criterion\MatchAll(); |
| 253 |
|
$query->query = $query->query ?: new Criterion\MatchAll(); |
| 254 |
|
|
| 255 |
|
if (count($query->facetBuilders)) { |
| 256 |
|
throw new NotImplementedException('Facets are not supported by the legacy search engine.'); |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
// The legacy search does not know about scores, so we just |
| 260 |
|
// combine the query with the filter |
| 261 |
|
$data = $this->locationGateway->find( |
| 262 |
|
new Criterion\LogicalAnd(array($query->query, $query->filter)), |
| 263 |
|
$query->offset, |
| 264 |
|
$query->limit, |
| 265 |
|
$query->sortClauses, |
| 266 |
|
$languageFilter, |
| 267 |
|
$query->performCount |
| 268 |
|
); |
| 269 |
|
|
| 270 |
|
$result = new SearchResult(); |
| 271 |
|
$result->time = microtime(true) - $start; |
| 272 |
|
$result->totalCount = $data['count']; |
| 273 |
|
$locationList = $this->locationMapper->createLocationsFromRows($data['rows']); |
| 274 |
|
|
| 275 |
|
foreach ($locationList as $index => $location) { |
| 276 |
|
$searchHit = new SearchHit(); |
| 277 |
|
$searchHit->valueObject = $location; |
| 278 |
|
$searchHit->matchedTranslation = $this->extractMatchedLanguage( |
| 279 |
|
$data['rows'][$index]['language_mask'], |
| 280 |
|
$data['rows'][$index]['initial_language_id'], |
| 281 |
|
$languageFilter |
| 282 |
|
); |
| 283 |
|
|
| 284 |
|
$result->searchHits[] = $searchHit; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
return $result; |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
/** |
| 291 |
|
* Suggests a list of values for the given prefix. |