-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from solariumphp/develop
Merging develop into master
- Loading branch information
Showing
41 changed files
with
2,212 additions
and
999 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ build | |
phpunit.xml | ||
composer.phar | ||
composer.lock | ||
vendor | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Contributing to Solarium | ||
|
||
So you consider contributing to Solarium? That’s great! | ||
Here are some pointers to hopefully get a good result. | ||
|
||
If you are uncertain about any part or need help please feel free to ask for help. | ||
|
||
## Bug reports | ||
|
||
* Bugs are intended for problems in the code or missing / faulty documentation. Not for issues with your own environment, questions in how to use feature X etcetera. | ||
* Include info about your environment: the version of Solarium you are using, PHP version, Solr version | ||
* If you get a specific error, include as much info as possible. The PHP exception, a Solr error log line, etcetera. | ||
* When something doesn't work as expected for you, also describe the behaviour you expect. | ||
* Do a quick search to check if the issue has already been reported | ||
* Describe your issue well, especially the title. Instead of ‘Select query exception’ use ‘Using a dash in a filterquery tag causes an exception’. | ||
* Provide steps to reproduce the issue. A unittest is ideal, but a description of manual steps is also very helpful. | ||
|
||
## Pull requests | ||
|
||
* Your pull requests should target the develop branch, not master. Nothing will be directly merged into master! | ||
* A pull request should be mergeable (fast-forward) if not, you will be asked to update it. | ||
* Ideally any change should include updated or new unittests to cover the changes. You can submit a PR without tests, but it will take longer to merge as someone else will need to fix the test coverage. | ||
* Solarium follows the Symfony2 code standards: http://symfony.com/doc/current/contributing/code/standards.html | ||
* Each PR will be checked by the CI environment automatically. Ofcourse anything other than a 'green' status needs to be fixed before a PR can be merged. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
require(__DIR__.'/init.php'); | ||
htmlHeader(); | ||
|
||
// create a client instance | ||
$client = new Solarium\Client($config); | ||
|
||
// get a select query instance | ||
$query = $client->createSelect(); | ||
|
||
// get the facetset component | ||
$facetSet = $query->getFacetSet(); | ||
|
||
// create a facet field instance and set options | ||
$facet = $facetSet->createFacetInterval('price'); | ||
$facet->setField('price'); | ||
$facet->setSet(array('1-9' => '[1,10)', '10-49' => '[10,50)', '49>' => '[50,*)')); | ||
|
||
// this executes the query and returns the result | ||
$resultset = $client->select($query); | ||
|
||
// display the total number of documents found by solr | ||
echo 'NumFound: '.$resultset->getNumFound(); | ||
|
||
// display facet counts | ||
echo '<hr/>Facet intervals:<br/>'; | ||
$facet = $resultset->getFacetSet()->getFacet('price'); | ||
foreach ($facet as $range => $count) { | ||
echo $range . ' to ' . ($range + 100) . ' [' . $count . ']<br/>'; | ||
} | ||
|
||
// show documents using the resultset iterator | ||
foreach ($resultset as $document) { | ||
|
||
echo '<hr/><table>'; | ||
echo '<tr><th>id</th><td>' . $document->id . '</td></tr>'; | ||
echo '<tr><th>name</th><td>' . $document->name . '</td></tr>'; | ||
echo '<tr><th>price</th><td>' . $document->price . '</td></tr>'; | ||
echo '</table>'; | ||
} | ||
|
||
htmlFooter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
<?php | ||
/** | ||
* Copyright 2011 Bas de Nooijer. All rights reserved. | ||
* Copyright 2012 Alexander Brausewetter. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this listof conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* The views and conclusions contained in the software and documentation are | ||
* those of the authors and should not be interpreted as representing official | ||
* policies, either expressed or implied, of the copyright holder. | ||
* | ||
* @copyright Copyright 2011 Bas de Nooijer <[email protected]> | ||
* @copyright Copyright 2012 Alexander Brausewetter <[email protected]> | ||
* @copyright Copyright 2014 Marin Purgar <[email protected]> | ||
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING | ||
* @link http://www.solarium-project.org/ | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Solarium\Core\Client\Adapter; | ||
|
||
use Solarium\Core\Configurable; | ||
use Solarium\Core\Client; | ||
use Solarium\Core\Client\Request; | ||
use Solarium\Core\Client\Response; | ||
use Solarium\Core\Client\Endpoint; | ||
use Solarium\Exception\HttpException; | ||
use Solarium\Exception\OutOfBoundsException; | ||
|
||
/** | ||
* Adapter that uses a ZF2 Zend\Http\Client | ||
* | ||
* The Zend Framework HTTP client has many great features and has lots of | ||
* configuration options. For more info see the manual at | ||
* {@link http://framework.zend.com/manual/en/zend.http.html} | ||
* | ||
* To use this adapter you need to have the Zend Framework available (autoloading) | ||
*/ | ||
class Zend2Http extends Configurable implements AdapterInterface | ||
{ | ||
/** | ||
* Zend Http instance for communication with Solr | ||
* | ||
* @var \Zend\Http\Client | ||
*/ | ||
protected $zendHttp; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $timeout; | ||
|
||
/** | ||
* Set options | ||
* | ||
* Overrides any existing values. | ||
* | ||
* If the options array has an 'options' entry it is forwarded to the | ||
* Zend\Http\Client. See the Zend\Http\Client docs for the many config | ||
* options available. | ||
* | ||
* The $options param should be an array or an object that has a toArray | ||
* method, like Zend_Config | ||
* | ||
* @param array|object $options | ||
* @param boolean $overwrite | ||
* @return self Provides fluent interface | ||
*/ | ||
public function setOptions($options, $overwrite = false) | ||
{ | ||
parent::setOptions($options, $overwrite); | ||
|
||
// forward options to zendHttp instance | ||
if (null !== $this->zendHttp) { | ||
|
||
// forward timeout setting | ||
$adapterOptions = array(); | ||
|
||
// forward adapter options if available | ||
if (isset($this->options['options'])) { | ||
$adapterOptions = array_merge($adapterOptions, $this->options['options']); | ||
} | ||
|
||
$this->zendHttp->setOptions($adapterOptions); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the Zend\Http\Client instance | ||
* | ||
* This method is optional, if you don't set a client it will be created | ||
* upon first use, using default and/or custom options (the most common use | ||
* case) | ||
* | ||
* @param \Zend\Http\Client $zendHttp | ||
* @return self Provides fluent interface | ||
*/ | ||
public function setZendHttp($zendHttp) | ||
{ | ||
$this->zendHttp = $zendHttp; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the Zend\Http\Client instance | ||
* | ||
* If no instance is available yet it will be created automatically based on | ||
* options. | ||
* | ||
* You can use this method to get a reference to the client instance to set | ||
* options, get the last response and use many other features offered by the | ||
* Zend\Http\Client API. | ||
* | ||
* @return \Zend\Http\Client | ||
*/ | ||
public function getZendHttp() | ||
{ | ||
if (null == $this->zendHttp) { | ||
$options = array(); | ||
|
||
// forward zendhttp options | ||
if (isset($this->options['options'])) { | ||
$options = array_merge( | ||
$options, | ||
$this->options['options'] | ||
); | ||
} | ||
|
||
$this->zendHttp = new \Zend\Http\Client(null, $options); | ||
} | ||
|
||
return $this->zendHttp; | ||
} | ||
|
||
/** | ||
* Execute a Solr request using the Zend\Http\Client instance | ||
* | ||
* @throws HttpException | ||
* @throws OutOfBoundsException | ||
* @param Request $request | ||
* @param Endpoint $endpoint | ||
* @return Response | ||
*/ | ||
public function execute($request, $endpoint) | ||
{ | ||
$client = $this->getZendHttp(); | ||
$client->resetParameters(); | ||
|
||
switch ($request->getMethod()) { | ||
case Request::METHOD_GET: | ||
$client->setMethod('GET'); | ||
$client->setParameterGet($request->getParams()); | ||
break; | ||
case Request::METHOD_POST: | ||
$client->setMethod('POST'); | ||
if ($request->getFileUpload()) { | ||
$this->prepareFileUpload($client, $request); | ||
} else { | ||
$client->setParameterGet($request->getParams()); | ||
$client->setRawBody($request->getRawData()); | ||
$request->addHeader('Content-Type: text/xml; charset=UTF-8'); | ||
} | ||
break; | ||
case Request::METHOD_HEAD: | ||
$client->setMethod('HEAD'); | ||
$client->setParameterGet($request->getParams()); | ||
break; | ||
default: | ||
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod()); | ||
break; | ||
} | ||
|
||
$client->setUri($endpoint->getBaseUri() . $request->getHandler()); | ||
$client->setHeaders($request->getHeaders()); | ||
$this->timeout = $endpoint->getTimeout(); | ||
|
||
$response = $client->send(); | ||
|
||
return $this->prepareResponse( | ||
$request, | ||
$response | ||
); | ||
} | ||
|
||
/** | ||
* Prepare a solarium response from the given request and client | ||
* response | ||
* | ||
* @throws HttpException | ||
* @param Request $request | ||
* @param \Zend\Http\Response $response | ||
* @return Response | ||
*/ | ||
protected function prepareResponse($request, $response) | ||
{ | ||
if ($response->isClientError()) { | ||
throw new HttpException( | ||
$response->getReasonPhrase(), | ||
$response->getStatusCode() | ||
); | ||
} | ||
|
||
if ($request->getMethod() == Request::METHOD_HEAD) { | ||
$data = ''; | ||
} else { | ||
$data = $response->getBody(); | ||
} | ||
|
||
// this is used because in ZF2 status line isn't in the headers anymore | ||
$headers = array($response->renderStatusLine()); | ||
|
||
return new Response($data, $headers); | ||
} | ||
|
||
/** | ||
* Prepare the client to send the file and params in request | ||
* | ||
* @param \Zend\Http\Client $client | ||
* @param Request $request | ||
* @return void | ||
*/ | ||
protected function prepareFileUpload($client, $request) | ||
{ | ||
$filename = $request->getFileUpload(); | ||
$client->setFileUpload( | ||
'content', | ||
'content', | ||
file_get_contents($filename), | ||
'application/octet-stream; charset=binary' | ||
); | ||
} | ||
} |
Oops, something went wrong.