Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Little Housekeeping #751

Merged
merged 1 commit into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions lib/Elastica/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AbstractUpdateAction extends Param
/**
* Sets the id of the document.
*
* @param string $id
* @param string $id
* @return \Elastica\Document
*/
public function setId($id)
Expand Down Expand Up @@ -49,7 +49,7 @@ public function hasId()
/**
* Sets lifetime of document
*
* @param string $ttl
* @param string $ttl
* @return \Elastica\Document
*/
public function setTtl($ttl)
Expand All @@ -76,7 +76,7 @@ public function hasTtl()
/**
* Sets the document type name
*
* @param string $type Type name
* @param string $type Type name
* @return \Elastica\Document Current object
*/
public function setType($type)
Expand All @@ -85,13 +85,14 @@ public function setType($type)
$this->setIndex($type->getIndex());
$type = $type->getName();
}

return $this->setParam('_type', $type);
}

/**
* Return document type name
*
* @return string Document type name
* @return string Document type name
* @throws \Elastica\Exception\InvalidException
*/
public function getType()
Expand All @@ -102,21 +103,22 @@ public function getType()
/**
* Sets the document index name
*
* @param string $index Index name
* @param string $index Index name
* @return \Elastica\Document Current object
*/
public function setIndex($index)
{
if ($index instanceof Index) {
$index = $index->getName();
}

return $this->setParam('_index', $index);
}

/**
* Get the document index name
*
* @return string Index name
* @return string Index name
* @throws \Elastica\Exception\InvalidException
*/
public function getIndex()
Expand All @@ -127,7 +129,7 @@ public function getIndex()
/**
* Sets the version of a document for use with optimistic concurrency control
*
* @param int $version Document version
* @param int $version Document version
* @return \Elastica\Document Current object
* @link http://www.elasticsearch.org/blog/2011/02/08/versioning.html
*/
Expand Down Expand Up @@ -158,7 +160,7 @@ public function hasVersion()
* Sets the version_type of a document
* Default in ES is internal, but you can set to external to use custom versioning
*
* @param int $versionType Document version type
* @param int $versionType Document version type
* @return \Elastica\Document Current object
* @link http://www.elasticsearch.org/guide/reference/api/index_.html
*/
Expand Down Expand Up @@ -188,7 +190,7 @@ public function hasVersionType()
/**
* Sets parent document id
*
* @param string|int $parent Parent document id
* @param string|int $parent Parent document id
* @return \Elastica\Document Current object
* @link http://www.elasticsearch.org/guide/reference/mapping/parent-field.html
*/
Expand Down Expand Up @@ -218,7 +220,7 @@ public function hasParent()
/**
* Set operation type
*
* @param string $opType Only accept create
* @param string $opType Only accept create
* @return \Elastica\Document Current object
*/
public function setOpType($opType)
Expand Down Expand Up @@ -246,7 +248,7 @@ public function hasOpType()
/**
* Set percolate query param
*
* @param string $value percolator filter
* @param string $value percolator filter
* @return \Elastica\Document
*/
public function setPercolate($value = '*')
Expand Down Expand Up @@ -275,7 +277,7 @@ public function hasPercolate()
/**
* Set routing query param
*
* @param string $value routing
* @param string $value routing
* @return \Elastica\Document
*/
public function setRouting($value)
Expand All @@ -302,14 +304,15 @@ public function hasRouting()
}

/**
* @param array|string $fields
* @param array|string $fields
* @return \Elastica\Document
*/
public function setFields($fields)
{
if (is_array($fields)) {
$fields = implode(',', $fields);
}

return $this->setParam('_fields', (string) $fields);
}

Expand Down Expand Up @@ -338,7 +341,7 @@ public function hasFields()
}

/**
* @param int $num
* @param int $num
* @return \Elastica\Document
*/
public function setRetryOnConflict($num)
Expand All @@ -363,7 +366,7 @@ public function hasRetryOnConflict()
}

/**
* @param string $timestamp
* @param string $timestamp
* @return \Elastica\Document
*/
public function setTimestamp($timestamp)
Expand All @@ -388,7 +391,7 @@ public function hasTimestamp()
}

/**
* @param bool $refresh
* @param bool $refresh
* @return \Elastica\Document
*/
public function setRefresh($refresh = true)
Expand All @@ -413,7 +416,7 @@ public function hasRefresh()
}

/**
* @param string $timeout
* @param string $timeout
* @return \Elastica\Document
*/
public function setTimeout($timeout)
Expand All @@ -438,7 +441,7 @@ public function hasTimeout()
}

/**
* @param string $timeout
* @param string $timeout
* @return \Elastica\Document
*/
public function setConsistency($timeout)
Expand All @@ -463,7 +466,7 @@ public function hasConsistency()
}

/**
* @param string $timeout
* @param string $timeout
* @return \Elastica\Document
*/
public function setReplication($timeout)
Expand All @@ -488,7 +491,7 @@ public function hasReplication()
}

/**
* @param \Elastica\Document|array $data
* @param \Elastica\Document|array $data
* @return \Elastica\Document
*/
public function setUpsert($data)
Expand Down Expand Up @@ -516,16 +519,16 @@ public function hasUpsert()
}

/**
* @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing
* @param bool $withUnderscore should option keys contain underscore prefix
* @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing
* @param bool $withUnderscore should option keys contain underscore prefix
* @return array
*/
public function getOptions(array $fields = array(), $withUnderscore = false)
{
if (!empty($fields)) {
$data = array();
foreach ($fields as $field) {
$key = '_' . ltrim($field, '_');
$key = '_'.ltrim($field, '_');
if ($this->hasParam($key) && '' !== (string) $this->getParam($key)) {
$data[$key] = $this->getParam($key);
}
Expand All @@ -539,6 +542,7 @@ public function getOptions(array $fields = array(), $withUnderscore = false)
unset($data[$key]);
}
}

return $data;
}
}
}
6 changes: 4 additions & 2 deletions lib/Elastica/Aggregation/AbstractAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getAggs()

/**
* Add a sub-aggregation
* @param AbstractAggregation $aggregation
* @param AbstractAggregation $aggregation
* @throws \Elastica\Exception\InvalidException
* @return AbstractAggregation
*/
Expand All @@ -67,6 +67,7 @@ public function addAggregation(AbstractAggregation $aggregation)
}

$this->_aggs[$aggregation->getName()] = $aggregation->toArray();

return $this;
}

Expand All @@ -78,11 +79,12 @@ public function toArray()
$array = parent::toArray();
if (array_key_exists('global_aggregation', $array)) {
// compensate for class name GlobalAggregation
$array = array('global' => new \stdClass);
$array = array('global' => new \stdClass());
}
if (sizeof($this->_aggs)) {
$array['aggs'] = $this->_aggs;
}

return $array;
}
}
9 changes: 5 additions & 4 deletions lib/Elastica/Aggregation/AbstractSimpleAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Elastica\Aggregation;


use Elastica\Script;

abstract class AbstractSimpleAggregation extends AbstractAggregation
{
/**
* Set the field for this aggregation
* @param string $field the name of the document field on which to perform this aggregation
* @param string $field the name of the document field on which to perform this aggregation
* @return AbstractSimpleAggregation
*/
public function setField($field)
Expand All @@ -19,15 +18,17 @@ public function setField($field)

/**
* Set a script for this aggregation
* @param string|Script $script
* @param string|Script $script
* @return AbstractSimpleAggregation
*/
public function setScript($script)
{
if ($script instanceof Script) {
$params = array_merge($this->getParams(), $script->toArray());

return $this->setParams($params);
}

return $this->setParam('script', $script);
}
}
}
4 changes: 1 addition & 3 deletions lib/Elastica/Aggregation/Avg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Elastica\Aggregation;


/**
* Class Avg
* @package Elastica\Aggregation
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-metrics-avg-aggregation.html
*/
class Avg extends AbstractSimpleAggregation
{

}
}
4 changes: 1 addition & 3 deletions lib/Elastica/Aggregation/Cardinality.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Elastica\Aggregation;


/**
* Class Cardinality
* @package Elastica\Aggregation
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
*/
class Cardinality extends AbstractSimpleAggregation
{

}
}
16 changes: 8 additions & 8 deletions lib/Elastica/Aggregation/DateHistogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DateHistogram extends Histogram
{
/**
* Set pre-rounding based on interval
* @param string $preZone
* @param string $preZone
* @return DateHistogram
*/
public function setPreZone($preZone)
Expand All @@ -21,7 +21,7 @@ public function setPreZone($preZone)

/**
* Set post-rounding based on interval
* @param string $postZone
* @param string $postZone
* @return DateHistogram
*/
public function setPostZone($postZone)
Expand All @@ -31,7 +31,7 @@ public function setPostZone($postZone)

/**
* Set pre-zone adjustment for larger time intervals (day and above)
* @param string $adjust
* @param string $adjust
* @return DateHistogram
*/
public function setPreZoneAdjustLargeInterval($adjust)
Expand All @@ -41,7 +41,7 @@ public function setPreZoneAdjustLargeInterval($adjust)

/**
* Adjust for granularity of date data
* @param int $factor set to 1000 if date is stored in seconds rather than milliseconds
* @param int $factor set to 1000 if date is stored in seconds rather than milliseconds
* @return DateHistogram
*/
public function setFactor($factor)
Expand All @@ -51,7 +51,7 @@ public function setFactor($factor)

/**
* Set the offset for pre-rounding
* @param string $offset "1d", for example
* @param string $offset "1d", for example
* @return DateHistogram
*/
public function setPreOffset($offset)
Expand All @@ -61,7 +61,7 @@ public function setPreOffset($offset)

/**
* Set the offset for post-rounding
* @param string $offset "1d", for example
* @param string $offset "1d", for example
* @return DateHistogram
*/
public function setPostOffset($offset)
Expand All @@ -72,11 +72,11 @@ public function setPostOffset($offset)
/**
* Set the format for returned bucket key_as_string values
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
* @param string $format see link for formatting options
* @param string $format see link for formatting options
* @return DateHistogram
*/
public function setFormat($format)
{
return $this->setParam("format", $format);
}
}
}
Loading