Skip to content

Commit

Permalink
Json elasticsearch removal (#1163)
Browse files Browse the repository at this point in the history
This constant was introduced for compatibility with PHP 5.3. This is now not needed anymore as PHP 5.3 compatibility was removed

* Remove JSON_ELASTICSEARCH constant as not needed anymore
* Run linter
  • Loading branch information
ruflin authored Aug 23, 2016
1 parent 0ffd884 commit 4237d1a
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 46 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ All notable changes to this project will be documented in this file based on the
### Improvements
- Set PHP 7.0 as default development version
- Get the root reason from Elasticsearch's error JSON, when available [#1111](https://github.com/ruflin/Elastica/pull/1111)
- Optimize memory usage for Http Adapter [#1161](https://github.com/ruflin/Elastica/pull/1161)

### Changed
- Remove JSON_ELASTICSEARCH constant as not needed anymore

## [3.2.1](https://github.com/ruflin/Elastica/compare/3.2.0...3.2.1)

Expand Down Expand Up @@ -52,8 +56,6 @@ All notable changes to this project will be documented in this file based on the
### Deprecated
- Configuring the logger in \Elastica\Client $config constructor is deprecated and will be removed. Use the $logger argument instead. [#1069](https://github.com/ruflin/Elastica/pull/1069)
- Extracted creation of ResultSet objects to a new dedicated ResultSet\Builder implementation. [#1065](https://github.com/ruflin/Elastica/pull/1065)

### Deprecated
- All properties in the \Elastica\ResultSet class will be moved to private in 4.0. To manipulate the creation of a ResultSet, implement the \Elastica\ResultSet\BuilderInterface and pass your new Builder to the \Elastica\Search instances. [#1065](https://github.com/ruflin/Elastica/pull/1065)


Expand Down
3 changes: 0 additions & 3 deletions lib/Elastica/Aggregation/GeoCentroid.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

namespace Elastica\Aggregation;

use Elastica\Exception\InvalidException;

/**
* Class GeoCentroid.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Bulk/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function toString()
$docAsUpsert = (isset($source['doc_as_upsert'])) ? ', "doc_as_upsert": '.$source['doc_as_upsert'] : '';
$string .= '{"doc": '.$source['doc'].$docAsUpsert.'}';
} else {
$string .= JSON::stringify($source, 'JSON_ELASTICSEARCH');
$string .= JSON::stringify($source, JSON_UNESCAPED_UNICODE);
}
$string .= Bulk::DELIMITER;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct(array $config = [], $callback = null, LoggerInterfac
}

/**
* Get current version
* Get current version.
*
* @return string
*/
Expand All @@ -104,6 +104,7 @@ public function getVersion()
}

$data = $this->request('/')->getData();

return $this->_version = $data['version']['number'];
}

Expand Down
5 changes: 0 additions & 5 deletions lib/Elastica/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public static function stringify(/* inherit from json_encode */)
// extract arguments
$args = func_get_args();

// allow special options value for Elasticsearch compatibility
if (count($args) > 1 && $args[1] === 'JSON_ELASTICSEARCH') {
$args[1] = JSON_UNESCAPED_UNICODE;
}

// run encode and output
return call_user_func_array('json_encode', $args);
}
Expand Down
17 changes: 8 additions & 9 deletions lib/Elastica/Query/FunctionScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class FunctionScore extends AbstractQuery
const MULTI_VALUE_MODE_AVG = 'avg';
const MULTI_VALUE_MODE_SUM = 'sum';


protected $_functions = [];

/**
Expand Down Expand Up @@ -134,14 +133,14 @@ public function addScriptScoreFunction(AbstractScript $script, $filter = null, $
/**
* Add a decay function to the query.
*
* @param string $function see DECAY_* constants for valid options
* @param string $field the document field on which to perform the decay function
* @param string $origin the origin value for this decay function
* @param string $scale a scale to define the rate of decay for this function
* @param string $offset If defined, this function will only be computed for documents with a distance from the origin greater than this value
* @param float $decay optionally defines how documents are scored at the distance given by the $scale parameter
* @param float $weight optional factor by which to multiply the score at the value provided by the $scale parameter
* @param AbstractQuery $filter a filter associated with this function
* @param string $function see DECAY_* constants for valid options
* @param string $field the document field on which to perform the decay function
* @param string $origin the origin value for this decay function

This comment has been minimized.

Copy link
@COil

COil Mar 22, 2018

Contributor

hi @ruflin , this origin typehint seems incorrect as it can be an array, right ?

    [ // center of the location circle
            'lat' => $parameters['lat'],
            'lon' => $parameters['lon'],
  ]

Edit: just saw the functionScoreTest, so concatenating lat and long is the preferred way?

This comment has been minimized.

Copy link
@ruflin

ruflin Mar 26, 2018

Author Owner

@COil The initial implementation is pretty old. So it could well be that for example in 2.x of Elasticsearch it was the preferred way but now there are others. In the end Elastic should support what is best for the user and from an Elasticsearch perspective.

Feel free to open a PR with a suggested change here. This will make discussing it much easier.

This comment has been minimized.

Copy link
@COil

COil Mar 26, 2018

Contributor

It's seems ok like this, thank you.

* @param string $scale a scale to define the rate of decay for this function
* @param string $offset If defined, this function will only be computed for documents with a distance from the origin greater than this value
* @param float $decay optionally defines how documents are scored at the distance given by the $scale parameter
* @param float $weight optional factor by which to multiply the score at the value provided by the $scale parameter
* @param AbstractQuery $filter a filter associated with this function
* @param string $multiValueMode see MULTI_VALUE_MODE_* constants for valid options
*
* @return $this
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Query/Fuzzy.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function setField($fieldName, $value)
* Set optional parameters on the existing query.
*
* @param string $option option name
* @param mixed $value Value of the parameter
* @param mixed $value Value of the parameter
*
* @return $this
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Elastica/Query/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function addTerm($term)
* Sets the minimum matching values.
*
* @param int|string $minimum Minimum value
* @return $this
*
* @return $this
*/
public function setMinimumMatch($minimum)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/QueryBuilder/DSL/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ public function template()
/**
* geo distance query.
*
* @param string $key
* @param string $key
* @param array|string $location
* @param string $distance
* @param string $distance
*
* @return GeoDistance
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Transport/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _createPsr7Request(Request $request, Connection $connection)

$req = $req->withBody(
Psr7\stream_for(is_array($data)
? JSON::stringify($data, 'JSON_ELASTICSEARCH')
? JSON::stringify($data, JSON_UNESCAPED_UNICODE)
: $data
)
);
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Transport/HttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function _createHttpAdapterRequest(ElasticaRequest $elasticaRequest, C
}

if (is_array($data)) {
$body = JSON::stringify($data, 'JSON_ELASTICSEARCH');
$body = JSON::stringify($data, JSON_UNESCAPED_UNICODE);
} else {
$body = $data;
}
Expand Down
18 changes: 9 additions & 9 deletions test/lib/Elastica/Test/Aggregation/GeoCentroidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ protected function _getIndexForTest()
$index = $this->_createIndex();
$type = $index->getType('test');

$type->setMapping(new Mapping(null, array(
'location' => array('type' => 'geo_point'),
)));

$type->addDocuments(array(
new Document(1, array('location' => array('lat' => 32.849437, 'lon' => -117.271732))),
new Document(2, array('location' => array('lat' => 32.798320, 'lon' => -117.246648))),
new Document(3, array('location' => array('lat' => 37.782439, 'lon' => -122.392560))),
));
$type->setMapping(new Mapping(null, [
'location' => ['type' => 'geo_point'],
]));

$type->addDocuments([
new Document(1, ['location' => ['lat' => 32.849437, 'lon' => -117.271732]]),
new Document(2, ['location' => ['lat' => 32.798320, 'lon' => -117.246648]]),
new Document(3, ['location' => ['lat' => 37.782439, 'lon' => -122.392560]]),
]);

$index->refresh();

Expand Down
4 changes: 2 additions & 2 deletions test/lib/Elastica/Test/Query/FunctionScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function testDecayWeight()
'origin' => $this->locationOrigin,
'scale' => $locationScale,
],
'multi_value_mode'=>FunctionScore::MULTI_VALUE_MODE_AVG,
'multi_value_mode' => FunctionScore::MULTI_VALUE_MODE_AVG,
],
'weight' => .5,
],
Expand All @@ -384,7 +384,7 @@ public function testDecayWeight()
'origin' => $priceOrigin,
'scale' => $priceScale,
],
'multi_value_mode'=>FunctionScore::MULTI_VALUE_MODE_MAX
'multi_value_mode' => FunctionScore::MULTI_VALUE_MODE_MAX,
],
'weight' => 2,
],
Expand Down
3 changes: 3 additions & 0 deletions test/lib/Elastica/Test/Query/IdsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public function testSetTypeArraySearchSingle()
$this->assertEquals(1, $resultSet->count());
}

/**
* @group unit
*/
public function testQueryTypeAndTypeCollision()
{
// This test ensures that Elastica\Type and Elastica\Query\Type
Expand Down
2 changes: 1 addition & 1 deletion test/lib/Elastica/Test/Query/QueryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testSearchMultipleFields()

$fields = [];
$max = rand() % 10 + 1;
for ($i = 0; $i < $max; ++$i) {
for ($i = 0; $i < $max; ++$i) {
$fields[] = md5(rand());
}

Expand Down
14 changes: 7 additions & 7 deletions test/lib/Elastica/Test/Query/TermsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ public function provideMinimumArguments()
{
return [
[
3
3,
],
[
-2
-2,
],
[
'75%'
'75%',
],
[
'-25%'
'-25%',
],
[
'3<90%'
'3<90%',
],
[
'2<-25% 9<-3'
]
'2<-25% 9<-3',
],
];
}

Expand Down

0 comments on commit 4237d1a

Please sign in to comment.