/** * Finds content objects for the given query. * * @todo define structs for the field filters * * @param \eZ\Publish\API\Repository\Values\Content\Query $query * @param array $fieldFilters - a map of filters for the returned fields. * Currently supported: <code>array("languages" => array(<language1>,..))</code>. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findContent(Query $query, array $fieldFilters = array()) { $parameters = array("q" => $this->criterionVisitor->visit($query->query), "fq" => $this->criterionVisitor->visit($query->filter), "sort" => implode(", ", array_map(array($this->sortClauseVisitor, "visit"), $query->sortClauses)), "fl" => "*,score", "wt" => "json"); if ($query->offset !== null) { $parameters["start"] = $query->offset; } if ($query->limit !== null) { $parameters["rows"] = $query->limit; } // @todo: Extract method $response = $this->client->request('GET', '/solr/select?' . http_build_query($parameters) . (count($query->facetBuilders) ? '&facet=true&facet.sort=count&' : '') . implode('&', array_map(array($this->facetBuilderVisitor, 'visit'), $query->facetBuilders))); // @todo: Error handling? $data = json_decode($response->body); // @todo: Extract method $result = new SearchResult(array('time' => $data->responseHeader->QTime / 1000, 'maxScore' => $data->response->maxScore, 'totalCount' => $data->response->numFound)); foreach ($data->response->docs as $doc) { $searchHit = new SearchHit(array('score' => $doc->score, 'valueObject' => $this->contentHandler->load($doc->id, $doc->version_id))); $result->searchHits[] = $searchHit; } if (isset($data->facet_counts)) { foreach ($data->facet_counts->facet_fields as $field => $facet) { $result->facets[] = $this->facetBuilderVisitor->map($field, $facet); } } return $result; }
/** * Deletes a location from the index. * * @param mixed $locationId * @param mixed $contentId */ public function deleteLocation($locationId, $contentId) { $this->gateway->deleteByQuery("content_id:{$contentId}"); // TODO it seems this part of location deletion (not last location) misses integration tests try { $contentInfo = $this->contentHandler->loadContentInfo($contentId); } catch (NotFoundException $e) { return; } $content = $this->contentHandler->load($contentId, $contentInfo->currentVersionNo); $this->bulkIndexContent(array($content)); }
/** * @param $locationId */ protected function updateAllElementsWithAdditionalLocation($locationId) { $query = $this->prepareQuery(); $query->filter = new Criterion\LogicalAnd([$this->allItemsWithinLocation($locationId), $this->allItemsWithinLocationWithAdditionalLocation($locationId)]); $searchResult = $this->resultExtractor->extract($this->gateway->searchAllEndpoints($query)); $contentItems = []; foreach ($searchResult->searchHits as $searchHit) { try { $contentInfo = $this->contentHandler->loadContentInfo($searchHit->valueObject->id); } catch (NotFoundException $e) { continue; } $contentItems[] = $this->contentHandler->load($contentInfo->id, $contentInfo->currentVersionNo); } $this->bulkIndexContent($contentItems); }
public function mapLocation(Location $location) { $contentInfo = $this->contentHandler->loadContentInfo($location->contentId); $content = $this->contentHandler->load($location->contentId, $contentInfo->currentVersionNo); $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId); $fields = array(new Field('location', $location->id, new FieldType\IdentifierField()), new Field('document_type', 'location', new FieldType\IdentifierField()), new Field('priority', $location->priority, new FieldType\IntegerField()), new Field('hidden', $location->hidden, new FieldType\BooleanField()), new Field('invisible', $location->invisible, new FieldType\BooleanField()), new Field('remote_id', $location->remoteId, new FieldType\IdentifierField()), new Field('parent_id', $location->parentId, new FieldType\IdentifierField()), new Field('path_string', $location->pathString, new FieldType\IdentifierField()), new Field('depth', $location->depth, new FieldType\IntegerField()), new Field('sort_field', $location->sortField, new FieldType\IdentifierField()), new Field('sort_order', $location->sortOrder, new FieldType\IdentifierField()), new Field('is_main_location', $location->id == $content->versionInfo->contentInfo->mainLocationId, new FieldType\BooleanField())); // UserGroups and Users are Content, but permissions cascade is achieved through // Locations hierarchy. We index all ancestor Location Content ids of all // Locations of an owner. $ancestorLocationsContentIds = $this->getAncestorLocationsContentIds($contentInfo->ownerId); // Add owner user id as it can also be considered as user group. $ancestorLocationsContentIds[] = $contentInfo->ownerId; $fields[] = new Field('content_owner_user_group', $ancestorLocationsContentIds, new FieldType\MultipleIdentifierField()); $fields[] = new Field('content_id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField()); $fields[] = new Field('content_type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField()); $fields[] = new Field('content_version', $content->versionInfo->versionNo, new FieldType\IdentifierField()); $fields[] = new Field('content_status', $content->versionInfo->status, new FieldType\IdentifierField()); $fields[] = new Field('content_name', $content->versionInfo->contentInfo->name, new FieldType\StringField()); $fields[] = new Field('content_creator', $content->versionInfo->creatorId, new FieldType\IdentifierField()); $fields[] = new Field('content_owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField()); $fields[] = new Field('content_section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField()); $fields[] = new Field('content_section_identifier', $section->identifier, new FieldType\IdentifierField()); $fields[] = new Field('content_section_name', $section->name, new FieldType\StringField()); $fields[] = new Field('content_remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField()); $fields[] = new Field('content_modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField()); $fields[] = new Field('content_published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField()); $fields[] = new Field('language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField()); $fields[] = new Field('content_always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField()); $fields[] = new Field('content_group', $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId)->groupIds, new FieldType\MultipleIdentifierField()); $fields[] = new Field('content_object_state', $this->getObjectStateIds($content->versionInfo->contentInfo->id), new FieldType\MultipleIdentifierField()); $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId); $fieldSets = $this->mapContentFields($content, $contentType, false); $documents = array(); foreach ($fieldSets as $languageCode => $translationFields) { $translationFields[] = new Field('meta_indexed_language_code', $languageCode, new FieldType\StringField()); $translationFields[] = new Field('meta_indexed_is_main_translation', $languageCode === $content->versionInfo->contentInfo->mainLanguageCode, new FieldType\BooleanField()); $translationFields[] = new Field('meta_indexed_is_main_translation_and_always_available', $languageCode === $content->versionInfo->contentInfo->mainLanguageCode && $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField()); $isMainTranslation = $content->versionInfo->contentInfo->mainLanguageCode === $languageCode; $alwaysAvailable = $isMainTranslation && $content->versionInfo->contentInfo->alwaysAvailable; $documents[] = new Document(array("id" => $this->generateLocationDocumentId($location, $languageCode), "languageCode" => $languageCode, "alwaysAvailable" => $alwaysAvailable, "isMainTranslation" => $isMainTranslation, "fields" => array_merge($fields, $translationFields))); } return $documents; }
/** * Maps given Location to a Document. * * Returned Document represents a "parent" Location document searchable with Location Search. * * @param \eZ\Publish\SPI\Persistence\Content\Location $location * * @return \eZ\Publish\Core\Search\Elasticsearch\Content\Document */ public function mapLocation(Location $location) { $contentInfo = $this->contentHandler->loadContentInfo($location->contentId); $content = $this->contentHandler->load($location->contentId, $contentInfo->currentVersionNo); $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId); $document = $this->mapContentLocation($location, $content); $document->id = $location->id; $document->type = "location"; $document->fields[] = new Field('is_main_location', $location->id == $content->versionInfo->contentInfo->mainLocationId, new FieldType\BooleanField()); // UserGroups and Users are Content, but permissions cascade is achieved through // Locations hierarchy. We index all ancestor Location Content ids of all // Locations of an owner. $ancestorLocationsContentIds = $this->getAncestorLocationsContentIds($contentInfo->ownerId); // Add owner user id as it can also be considered as user group. $ancestorLocationsContentIds[] = $contentInfo->ownerId; $document->fields[] = new Field('content_owner_user_group', $ancestorLocationsContentIds, new FieldType\MultipleIdentifierField()); $document->fields[] = new Field('content_id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField()); $document->fields[] = new Field('content_type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField()); $document->fields[] = new Field('content_version', $content->versionInfo->versionNo, new FieldType\IdentifierField()); $document->fields[] = new Field('content_status', $content->versionInfo->status, new FieldType\IdentifierField()); $document->fields[] = new Field('content_name', $content->versionInfo->contentInfo->name, new FieldType\StringField()); $document->fields[] = new Field('content_creator', $content->versionInfo->creatorId, new FieldType\IdentifierField()); $document->fields[] = new Field('content_owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField()); $document->fields[] = new Field('content_section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField()); $document->fields[] = new Field('content_section_identifier', $section->identifier, new FieldType\IdentifierField()); $document->fields[] = new Field('content_section_name', $section->name, new FieldType\StringField()); $document->fields[] = new Field('content_remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField()); $document->fields[] = new Field('content_modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField()); $document->fields[] = new Field('content_published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField()); $document->fields[] = new Field('content_language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField()); $document->fields[] = new Field('content_always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField()); $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId); $document->fields[] = new Field('content_group', $contentType->groupIds, new FieldType\MultipleIdentifierField()); $document->fields[] = new Field('content_object_state', $this->getObjectStateIds($content->versionInfo->contentInfo->id), new FieldType\MultipleIdentifierField()); return $document; }