Exemplo n.º 1
0
 /**
  * Map field value to a proper Solr representation
  *
  * @param Criterion $criterion
  * @param CriterionVisitor $subVisitor
  *
  * @return string
  */
 public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null)
 {
     if (!isset($criterion->criteria[0]) || count($criterion->criteria) > 1) {
         throw new \RuntimeException("Invalid aggregation in LogicalNot criterion.");
     }
     return '(*:* NOT (' . $subVisitor->visit($criterion->criteria[0]) . '))';
 }
Exemplo n.º 2
0
 /**
  * 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' => new SPIContentInfo(array('id' => $doc->id, '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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Map field value to a proper Solr representation
  *
  * @param Criterion $criterion
  * @param CriterionVisitor $subVisitor
  *
  * @return string
  */
 public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null)
 {
     return '(' . implode(' AND ', array_map(function ($value) use($subVisitor) {
         return $subVisitor->visit($value);
     }, $criterion->criteria)) . ')';
 }