/** * Finds content objects for the given query. * * @todo define structs for the field filters * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid * * @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>. * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findContent(Query $query, array $fieldFilters = array(), $filterOnUserPermissions = true) { $solrserverconfig = Globals::getSolrServerConfig(); $solrglobalconfig = Globals::getSolrGlobalConfig(); $client = new \Solarium\Client($solrserverconfig); $query = clone $query; $query->filter = $query->filter ?: new Criterion\MatchAll(); $this->validateContentCriteria(array($query->query), "\$query"); $this->validateContentCriteria(array($query->filter), "\$query"); $this->validateContentSortClauses($query); $this->validateSortClauses($query); if ($query->limit === null) { $query->limit = 2; } $criterion = $query->query; $queries = array("" . $criterion->value); foreach ($criterion->boost as $field => $boost) { $fields = $this->fieldMap->getFieldTypes($criterion); if (!isset($fields[$field])) { continue; } foreach ($fields[$field] as $fieldNames) { foreach ($fieldNames as $fieldName) { $queries[] = $fieldName . ":" . $criterion->value . "^" . $boost; } } } $abfrage = "(" . implode(') OR (', array_map(function ($search) use($criterion) { return $search . ($criterion->fuzziness < 1 ? sprintf("~%.1f", $criterion->fuzziness) : ""); }, $queries)) . ")"; if ($query->offset !== null) { $parameters["start"] = $query->offset; } if ($query->limit !== null) { $parameters["rows"] = $query->limit; } // @todo: Extract method $solrquery = $client->createQuery($client::QUERY_SELECT); $solrquery->createFilterQuery('solrdocs')->setQuery("is_solrdoc_b:true AND " . $abfrage); $result = $client->select($solrquery); // @todo: Extract method $result = new SearchResult(array('time' => $data->responseHeader->QTime / 1000, 'maxScore' => $data->response->maxScore, 'totalCount' => $data->response->numFound)); foreach ($result as $doc) { $searchHit = new SearchHit(array('score' => $doc->score, 'valueObject' => $doc)); #'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); } } var_dump($result); die("Stop"); return $result; }
<?php require __DIR__ . '/init.php'; htmlHeader(); // create a client instance $client = new Solarium\Client($config); // get a select query instance $query = $client->createQuery($client::QUERY_SELECT); // this executes the query and returns the result $resultset = $client->execute($query); // display the total number of documents found by solr echo 'NumFound: ' . $resultset->getNumFound(); // show documents using the resultset iterator foreach ($resultset as $document) { echo '<hr/><table>'; // the documents are also iterable, to get all fields foreach ($document as $field => $value) { // this converts multivalue fields to a comma-separated string if (is_array($value)) { $value = implode(', ', $value); } echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; } echo '</table>'; } htmlFooter();
<?php require __DIR__ . '/init.php'; htmlHeader(); // create a client instance $client = new Solarium\Client($config); // enable the filter plugin and get a query instance $filter = $client->getPlugin('minimumscorefilter'); $query = $client->createQuery($filter::QUERY_TYPE); $query->setRows(50); $query->setFields(array('id', 'name', 'score')); $query->setQuery('memory'); $query->setFilterRatio(0.8); $query->setFilterMode($query::FILTER_MODE_MARK); // get grouping component and set a field to group by $groupComponent = $query->getGrouping(); $groupComponent->addField('inStock'); // maximum number of items per group $groupComponent->setLimit(10); // get a group count $groupComponent->setNumberOfGroups(true); // this executes the query and returns the result $resultset = $client->select($query); $groups = $resultset->getGrouping(); foreach ($groups as $groupKey => $fieldGroup) { echo '<h1>' . $groupKey . '</h1>'; echo 'Matches: ' . $fieldGroup->getMatches() . '<br/>'; echo 'Number of groups: ' . $fieldGroup->getNumberOfGroups(); foreach ($fieldGroup as $valueGroup) { echo '<h2>' . (int) $valueGroup->getValue() . '</h2>'; foreach ($valueGroup as $document) {