Skip to content

Commit

Permalink
Merge pull request #339 from solariumphp/develop
Browse files Browse the repository at this point in the history
Merging develop into master
  • Loading branch information
basdenooijer committed Jun 14, 2015
2 parents 243ef1f + 597b6c1 commit a9c1c5f
Show file tree
Hide file tree
Showing 41 changed files with 2,212 additions and 999 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ build
phpunit.xml
composer.phar
composer.lock
vendor
vendor
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# CHANGELOG

## 3.4.0 - 2015-06-14

- bugfix: only check type for added documents to add query if provided as an array
- improvement: added support for calling empty() and isset() on result document properties
- improvement: added composer test script
- bugfix: curl file upload handling
- improvement: added 'contributing' file
- improvement: docblock fixes in grouping component facets
- added: facet interval support
- added: ZF2 http adapter
- added: stats for pivot facet
- bugfix: spellcheck 'collations' and 'correctlyspelled' updated to support Solr 5 format
- bugfix: curl adapter now uses Solr 5 compatible headers for a GET request
- improvement: lots of code style fixes, using the SF2 code style


## 3.3.0 - 2014-11-16

- improvement: fixes in build.xml (use phpunit in vendor directory)
Expand Down
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
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.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ http://wiki.solarium-project.org/index.php/V3:Installation#Getting_Solarium
* Develop branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=develop)](https://coveralls.io/r/solariumphp/solarium?branch=develop)
* Master branch [![Develop build status](https://secure.travis-ci.org/solariumphp/solarium.png?branch=master)](http://travis-ci.org/solariumphp/solarium)
* Master branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=master)](https://coveralls.io/r/solariumphp/solarium?branch=master)


43 changes: 43 additions & 0 deletions examples/2.1.5.1.6-facet-interval.php
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();
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h1>Solarium examples</h1>
<li><a href="2.1.5.1.3-facet-multiquery.php">2.1.5.1.3 Facet multiquery</a></li>
<li><a href="2.1.5.1.4-facet-range.php">2.1.5.1.4 Facet range</a></li>
<li><a href="2.1.5.1.5-facet-pivot.php">2.1.5.1.5 Facet pivot</a></li>
<li><a href="2.1.5.1.6-facet-interval.php">2.1.5.1.6 Facet interval</a></li>
</ul>
<li><a href="2.1.5.2-morelikethis.php">2.1.5.2 MoreLikeThis</a></li>
<li><a href="2.1.5.3-highlighting.php">2.1.5.3 Highlighting</a></li>
Expand Down
2 changes: 1 addition & 1 deletion library/Solarium/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Client extends CoreClient
*
* @var string
*/
const VERSION = '3.2.0';
const VERSION = '3.4.0';

/**
* Check for an exact version
Expand Down
2 changes: 1 addition & 1 deletion library/Solarium/Core/Client/Adapter/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function createHandle($request, $endpoint)
if ($request->getFileUpload()) {
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
$curlFile = curl_file_create($request->getFileUpload());
curl_setopt($handler, CURLOPT_POSTFIELDS, array('content', $curlFile));
curl_setopt($handler, CURLOPT_POSTFIELDS, array('content' => $curlFile));
} else {
curl_setopt($handler, CURLOPT_POSTFIELDS, array('content' => '@'.$request->getFileUpload()));
}
Expand Down
257 changes: 257 additions & 0 deletions library/Solarium/Core/Client/Adapter/Zend2Http.php
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'
);
}
}
Loading

0 comments on commit a9c1c5f

Please sign in to comment.