コード例 #1
0
ファイル: Native.php プロジェクト: Jenkosama/ezpublish-kernel
 /**
  * Finds Location objects for the given query.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findLocations(LocationQuery $query)
 {
     $parameters = array("q" => 'document_type_id:"location" AND ' . $this->criterionVisitor->visit($query->query), "fq" => 'document_type_id:"location" AND ' . $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);
     if (!isset($data->response)) {
         throw new \Exception('->response not set: ' . var_export(array($data, $parameters), true));
     }
     // @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->locationHandler->load(substr($doc->id, 8))));
         $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;
 }
コード例 #2
0
ファイル: Native.php プロジェクト: Jenkosama/ezpublish-kernel
 /**
  * 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" => 'document_type_id:"content" AND ' . $this->criterionVisitor->visit($query->query), "fq" => 'document_type_id:"content" AND ' . $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);
     if (!isset($data->response)) {
         throw new \Exception('->response not set: ' . var_export(array($data, $parameters), true));
     }
     // @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' => new SPIContentInfo(array('id' => substr($doc->id, 7), 'name' => $doc->name_s, 'contentTypeId' => $doc->type_id, 'sectionId' => $doc->section_id, 'currentVersionNo' => $doc->version_id, 'isPublished' => $doc->status_id === SPIContentInfo::STATUS_PUBLISHED, 'ownerId' => $doc->owner_id, 'modificationDate' => $doc->modified_dt, 'publicationDate' => $doc->published_dt, 'alwaysAvailable' => $doc->always_available_b, 'remoteId' => $doc->remote_id_id, 'mainLanguageCode' => $doc->main_language_code_s, 'mainLocationId' => isset($doc->main_location_id) ? $doc->main_location_id : null))));
         $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;
 }