diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-08-16 08:22:05 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-08-16 08:22:05 +0200 |
commit | 1a365e77dfb8825136626202b1df462731b42060 (patch) | |
tree | 1dc4468eaabf070e051e790a9e67a9a9a2c63d99 /vendor/ruflin/elastica/lib/Elastica/Query | |
parent | a72fd280f7acb4d2a1ba579a0f1b2b2ae8958530 (diff) |
Update to MediaWiki 1.25.2
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Query')
28 files changed, 3526 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/AbstractQuery.php b/vendor/ruflin/elastica/lib/Elastica/Query/AbstractQuery.php new file mode 100644 index 00000000..5b24ace4 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/AbstractQuery.php @@ -0,0 +1,15 @@ +<?php + +namespace Elastica\Query; +use Elastica\Param; + +/** + * Abstract query object. Should be extended by all query types. + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + */ +abstract class AbstractQuery extends Param +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Bool.php b/vendor/ruflin/elastica/lib/Elastica/Query/Bool.php new file mode 100644 index 00000000..2b2c1157 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Bool.php @@ -0,0 +1,92 @@ +<?php + +namespace Elastica\Query; +use Elastica\Exception\InvalidException; +use Elastica\Query\AbstractQuery; + +/** + * Bool query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html + */ +class Bool extends AbstractQuery +{ + /** + * Add should part to query + * + * @param \Elastica\Query\AbstractQuery|array $args Should query + * @return \Elastica\Query\Bool Current object + */ + public function addShould($args) + { + return $this->_addQuery('should', $args); + } + + /** + * Add must part to query + * + * @param \Elastica\Query\AbstractQuery|array $args Must query + * @return \Elastica\Query\Bool Current object + */ + public function addMust($args) + { + return $this->_addQuery('must', $args); + } + + /** + * Add must not part to query + * + * @param \Elastica\Query\AbstractQuery|array $args Must not query + * @return \Elastica\Query\Bool Current object + */ + public function addMustNot($args) + { + return $this->_addQuery('must_not', $args); + } + + /** + * Adds a query to the current object + * + * @param string $type Query type + * @param \Elastica\Query\AbstractQuery|array $args Query + * @return \Elastica\Query\Bool + * @throws \Elastica\Exception\InvalidException If not valid query + */ + protected function _addQuery($type, $args) + { + if ($args instanceof AbstractQuery) { + $args = $args->toArray(); + } + + if (!is_array($args)) { + throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); + } + + return $this->addParam($type, $args); + } + + /** + * Sets boost value of this query + * + * @param float $boost Boost value + * @return \Elastica\Query\Bool Current object + */ + public function setBoost($boost) + { + return $this->setParam('boost', $boost); + } + + /** + * Set the minimum number of of should match + * + * @param int $minimumNumberShouldMatch Should match minimum + * @return \Elastica\Query\Bool Current object + */ + public function setMinimumNumberShouldMatch($minimumNumberShouldMatch) + { + return $this->setParam('minimum_number_should_match', $minimumNumberShouldMatch); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Boosting.php b/vendor/ruflin/elastica/lib/Elastica/Query/Boosting.php new file mode 100644 index 00000000..fe429637 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Boosting.php @@ -0,0 +1,44 @@ +<?php + +namespace Elastica\Query; + +/** + * Class Boosting + * @package Elastica\Query + * @author Balazs Nadasdi <yitsushi@gmail.com> + * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html + */ +class Boosting extends AbstractQuery +{ + const NEGATIVE_BOOST = 0.2; + + /** + * Set the positive query for this Boosting Query + * @param AbstractQuery $query + * @return \Elastica\Query\Boosting + */ + public function setPositiveQuery(AbstractQuery $query) + { + return $this->setParam('positive', $query->toArray()); + } + + /** + * Set the negative query for this Boosting Query + * @param AbstractQuery $query + * @return \Elastica\Query\Boosting + */ + public function setNegativeQuery(AbstractQuery $query) + { + return $this->setParam('negative', $query->toArray()); + } + + /** + * Set the negative_boost parameter for this Boosting Query + * @param Float $negativeBoost + * @return \Elastica\Query\Boosting + */ + public function setNegativeBoost($negativeBoost) + { + return $this->setParam('negative_boost', (float)$negativeBoost); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Builder.php b/vendor/ruflin/elastica/lib/Elastica/Query/Builder.php new file mode 100644 index 00000000..2a5e8baa --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Builder.php @@ -0,0 +1,933 @@ +<?php + +namespace Elastica\Query; + +use Elastica\Exception\InvalidException; +use Elastica\Exception\JSONParseException; +use Elastica\JSON; + +/** + * Query Builder. + * + * @category Xodoa + * @package Elastica + * @author Chris Gedrim <chris@gedr.im> + * @link http://www.elasticsearch.org/ + **/ +class Builder extends AbstractQuery +{ + /** + * Query string. + * + * @var string + */ + private $_string = '{'; + + /** + * Factory method. + * + * @param string $string JSON encoded string to use as query. + * + * @return \Elastica\Query\Builder + */ + public static function factory($string = null) + { + return new Builder($string); + } + + /** + * Constructor + * + * @param string $string JSON encoded string to use as query. + */ + public function __construct($string = null) + { + if (! $string == null) { + $this->_string .= substr($string, 1, -1); + } + } + + /** + * Output the query string. + * + * @return string + */ + public function __toString() + { + return rtrim($this->_string, ',').'}'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + try { + return JSON::parse($this->__toString()); + } catch (JSONParseException $e) { + throw new InvalidException('The query produced is invalid'); + } + } + + /** + * Allow wildcards (*, ?) as the first character in a query. + * + * @param boolean $bool Defaults to true. + * + * @return \Elastica\Query\Builder + */ + public function allowLeadingWildcard($bool = true) + { + return $this->field('allow_leading_wildcard', (bool) $bool); + } + + /** + * Enable best effort analysis of wildcard terms. + * + * @param boolean $bool Defaults to true. + * + * @return \Elastica\Query\Builder + */ + public function analyzeWildcard($bool = true) + { + return $this->field('analyze_wildcard', (bool) $bool); + } + + /** + * Set the analyzer name used to analyze the query string. + * + * @param string $analyzer Analyzer to use. + * + * @return \Elastica\Query\Builder + */ + public function analyzer($analyzer) + { + return $this->field('analyzer', $analyzer); + } + + /** + * Autogenerate phrase queries. + * + * @param boolean $bool Defaults to true. + * + * @return \Elastica\Query\Builder + */ + public function autoGeneratePhraseQueries($bool = true) + { + return $this->field('auto_generate_phrase_queries', (bool) $bool); + } + + /** + * Bool Query. + * + * A query that matches documents matching boolean combinations of other queries. + * + * The bool query maps to Lucene BooleanQuery. + * + * It is built using one or more boolean clauses, each clause with a typed + * occurrence. + * + * The occurrence types are: must, should, must_not. + * + * @return \Elastica\Query\Builder + */ + public function bool() + { + return $this->fieldOpen('bool'); + } + + /** + * Close a 'bool' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function boolClose() + { + return $this->fieldClose(); + } + + /** + * Sets the boost value of the query. + * + * @param float $boost Defaults to 1.0. + * + * @return \Elastica\Query\Builder + */ + public function boost($boost = 1.0) + { + return $this->field('boost', (float) $boost); + } + + /** + * Close a previously opened brace. + * + * @return \Elastica\Query\Builder + */ + public function close() + { + $this->_string = rtrim($this->_string, ' ,').'},'; + + return $this; + } + + /** + * Constant Score Query. + * + * A query that wraps a filter or another query and simply returns a constant + * score equal to the query boost for every document in the filter. + * + * Maps to Lucene ConstantScoreQuery. + * + * @return \Elastica\Query\Builder + */ + public function constantScore() + { + return $this->fieldOpen('constant_score'); + } + + /** + * Close a 'constant_score' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function constantScoreClose() + { + return $this->fieldClose(); + } + + /** + * The default field for query terms if no prefix field is specified. + * + * @param string $field Defaults to _all. + * + * @return \Elastica\Query\Builder + */ + public function defaultField($field = '_all') + { + return $this->field('default_field', $field); + } + + /** + * The default operator used if no explicit operator is specified. + * + * For example, with a default operator of OR, the query "capital of Hungary" + * is translated to "capital OR of OR Hungary", and with default operator of + * AND, the same query is translated to "capital AND of AND Hungary". + * + * @param string $operator Defaults to OR. + * + * @return \Elastica\Query\Builder + */ + public function defaultOperator($operator = 'OR') + { + return $this->field('default_operator', $operator); + } + + /** + * Dis Max Query. + * + * A query that generates the union of documents produced by its subqueries, + * and that scores each document with the maximum score for that document as + * produced by any subquery, plus a tie breaking increment for any additional + * matching subqueries. + * + * @return \Elastica\Query\Builder + */ + public function disMax() + { + return $this->fieldOpen('dis_max'); + } + + /** + * Close a 'dis_max' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function disMaxClose() + { + return $this->fieldClose(); + } + + /** + * Enable position increments in result queries. + * + * @param boolean $bool Defaults to true. + * + * @return \Elastica\Query\Builder + */ + public function enablePositionIncrements($bool = true) + { + return $this->field('enable_position_increments', (bool) $bool); + } + + /** + * Enables explanation for each hit on how its score was computed. + * + * @param boolean $value Turn on / off explain. + * + * @return \Elastica\Query\Builder + */ + public function explain($value = true) + { + return $this->field('explain', $value); + } + + /** + * Open 'facets' block. + * + * Facets provide aggregated data based on a search query. + * + * In the simple case, a facet can return facet counts for various facet + * values for a specific field. + * + * Elasticsearch supports more advanced facet implementations, such as + * statistical or date histogram facets. + * + * @return \Elastica\Query\Builder + */ + public function facets() + { + return $this->fieldOpen('facets'); + } + + /** + * Close a facets block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function facetsClose() + { + return $this->close(); + } + + /** + * Add a specific field / value entry. + * + * @param string $name Field to add. + * @param mixed $value Value to set. + * + * @return \Elastica\Query\Builder + */ + public function field($name, $value) + { + if (is_bool($value)) { + $value = '"'. var_export($value, true) . '"'; + } elseif (is_array($value)) { + $value = '["'.implode('","', $value).'"]'; + } else { + $value = '"'.$value.'"'; + } + + $this->_string .= '"'.$name.'":'.$value.','; + + return $this; + } + + /** + * Close a field block. + * + * Alias of close() for ease of reading in source. + * Passed parameters will be ignored, however they can be useful in source for + * seeing which field is being closed. + * + * Builder::factory() + * ->query() + * ->range() + * ->fieldOpen('created') + * ->gte('2011-07-18 00:00:00') + * ->lt('2011-07-19 00:00:00') + * ->fieldClose('created') + * ->rangeClose() + * ->queryClose(); + * + * @return \Elastica\Query\Builder + */ + public function fieldClose() + { + return $this->close(); + } + + /** + * Open a node for the specified name. + * + * @param string $name Field name. + * + * @return \Elastica\Query\Builder + */ + public function fieldOpen($name) + { + $this->_string .= '"'.$name.'":'; + $this->open(); + + return $this; + } + + /** + * Explicitly define fields to return. + * + * @param array $fields Array of fields to return. + * + * @return \Elastica\Query\Builder + */ + public function fields(array $fields) + { + $this->_string .= '"fields":['; + + foreach ($fields as $field) { + $this->_string .= '"'.$field.'",'; + } + + $this->_string = rtrim($this->_string, ',').'],'; + + return $this; + } + + /** + * Open a 'filter' block. + * + * @return \Elastica\Query\Builder + */ + public function filter() + { + return $this->fieldOpen('filter'); + } + + /** + * Close a filter block. + * + * @return \Elastica\Query\Builder + */ + public function filterClose() + { + return $this->close(); + } + + /** + * Query. + * + * @return \Elastica\Query\Builder + */ + public function filteredQuery() + { + return $this->fieldOpen('filtered'); + } + + /** + * Close a 'filtered_query' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function filteredQueryClose() + { + return $this->fieldClose(); + } + + /** + * Set the from parameter (offset). + * + * @param integer $value Result number to start from. + * + * @return \Elastica\Query\Builder + */ + public function from($value = 0) + { + return $this->field('from', $value); + } + + /** + * Set the minimum similarity for fuzzy queries. + * + * @param float $value Defaults to 0.5. + * + * @return \Elastica\Query\Builder + */ + public function fuzzyMinSim($value = 0.5) + { + return $this->field('fuzzy_min_sim', (float) $value); + } + + /** + * Set the prefix length for fuzzy queries. + * + * @param integer $value Defaults to 0. + * + * @return \Elastica\Query\Builder + */ + public function fuzzyPrefixLength($value = 0) + { + return $this->field('fuzzy_prefix_length', (int) $value); + } + + /** + * Add a greater than (gt) clause. + * + * Used in range blocks. + * + * @param mixed $value Value to be gt. + * + * @return \Elastica\Query\Builder + */ + public function gt($value) + { + return $this->field('gt', $value); + } + + /** + * Add a greater than or equal to (gte) clause. + * + * Used in range blocks. + * + * @param mixed $value Value to be gte to. + * + * @return \Elastica\Query\Builder + */ + public function gte($value) + { + return $this->field('gte', $value); + } + + /** + * Automatically lower-case terms of wildcard, prefix, fuzzy, and range queries. + * + * @param boolean $bool Defaults to true. + * + * @return \Elastica\Query\Builder + */ + public function lowercaseExpandedTerms($bool = true) + { + return $this->field('lowercase_expanded_terms', (bool) $bool); + } + + /** + * Add a less than (lt) clause. + * + * Used in range blocks. + * + * @param mixed $value Value to be lt. + * + * @return \Elastica\Query\Builder + */ + public function lt($value) + { + return $this->field('lt', $value); + } + + /** + * Add a less than or equal to (lte) clause. + * + * Used in range blocks. + * + * @param mixed $value Value to be lte to. + * + * @return \Elastica\Query\Builder + */ + public function lte($value) + { + return $this->field('lte', $value); + } + + /** + * Match All Query. + * + * A query that matches all documents. + * + * Maps to Lucene MatchAllDocsQuery. + * + * @param float $boost Boost to use. + * + * @return \Elastica\Query\Builder + */ + public function matchAll($boost = null) + { + $this->fieldOpen('match_all'); + + if ( ! $boost == null && is_numeric($boost)) { + $this->field('boost', (float) $boost); + } + + return $this->close(); + } + + /** + * The minimum number of should clauses to match. + * + * @param integer $minimum Minimum number that should match. + * + * @return \Elastica\Query\Builder + */ + public function minimumNumberShouldMatch($minimum) + { + return $this->field('minimum_number_should_match', (int) $minimum); + } + + /** + * The clause (query) must appear in matching documents. + * + * @return \Elastica\Query\Builder + */ + public function must() + { + return $this->fieldOpen('must'); + } + + /** + * Close a 'must' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function mustClose() + { + return $this->fieldClose(); + } + + /** + * The clause (query) must not appear in the matching documents. + * + * Note that it is not possible to search on documents that only consists of + * a must_not clauses. + * + * @return \Elastica\Query\Builder + */ + public function mustNot() + { + return $this->fieldOpen('must_not'); + } + + /** + * Close a 'must_not' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function mustNotClose() + { + return $this->fieldClose(); + } + + /** + * Add an opening brace. + * + * @return \Elastica\Query\Builder + */ + public function open() + { + $this->_string .= '{'; + + return $this; + } + + /** + * Sets the default slop for phrases. + * + * If zero, then exact phrase matches are required. + * + * @param integer $value Defaults to 0. + * + * @return \Elastica\Query\Builder + */ + public function phraseSlop($value = 0) + { + return $this->field('phrase_slop', (int) $value); + } + + /** + * Query. + * + * @return \Elastica\Query\Builder + */ + public function prefix() + { + return $this->fieldOpen('prefix'); + } + + /** + * Close a 'prefix' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function prefixClose() + { + return $this->fieldClose(); + } + + /** + * Queries to run within a dis_max query. + * + * @param array $queries Array of queries. + * + * @return \Elastica\Query\Builder + */ + public function queries(array $queries) + { + $this->_string .= '"queries":['; + + foreach ($queries as $query) { + $this->_string .= $query.','; + } + + $this->_string = rtrim($this->_string, ' ,').'],'; + + return $this; + } + + /** + * Open a query block. + * + * @return \Elastica\Query\Builder + */ + public function query() + { + return $this->fieldOpen('query'); + } + + /** + * Close a query block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function queryClose() + { + return $this->close(); + } + + /** + * Query String Query. + * + * A query that uses a query parser in order to parse its content + * + * @return \Elastica\Query\Builder + */ + public function queryString() + { + return $this->fieldOpen('query_string'); + } + + /** + * Close a 'query_string' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function queryStringClose() + { + return $this->fieldClose(); + } + + /** + * Open a range block. + * + * @return \Elastica\Query\Builder + */ + public function range() + { + return $this->fieldOpen('range'); + } + + /** + * Close a range block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function rangeClose() + { + return $this->close(); + } + + /** + * The clause (query) should appear in the matching document. + * + * A boolean query with no must clauses, one or more should clauses must + * match a document. + * + * @return \Elastica\Query\Builder + */ + public function should() + { + return $this->fieldOpen('should'); + } + + /** + * Close a 'should' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function shouldClose() + { + return $this->fieldClose(); + } + + /** + * Set the size parameter (number of records to return). + * + * @param integer $value Number of records to return. + * + * @return \Elastica\Query\Builder + */ + public function size($value = 10) + { + return $this->field('size', $value); + } + + /** + * Allows to add one or more sort on specific fields. + * + * @return \Elastica\Query\Builder + */ + public function sort() + { + return $this->fieldOpen('sort'); + } + + /** + * Close a sort block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function sortClose() + { + return $this->close(); + } + + /** + * Add a field to sort on. + * + * @param string $name Field to sort. + * @param boolean $reverse Reverse direction. + * + * @return \Elastica\Query\Builder + */ + public function sortField($name, $reverse = false) + { + return $this + ->fieldOpen('sort') + ->fieldOpen($name) + ->field('reverse', $reverse) + ->close() + ->close(); + } + + /** + * Sort on multiple fields + * + * @param array $fields Associative array where the keys are field names to sort on, and the + * values are the sort order: "asc" or "desc" + * + * @return \Elastica\Query\Builder + */ + public function sortFields(array $fields) + { + $this->_string .= '"sort":['; + + foreach ($fields as $fieldName => $order) { + $this->_string .= '{"'.$fieldName.'":"'.$order.'"},'; + } + + $this->_string = rtrim($this->_string, ',') . '],'; + + return $this; + } + + /** + * Term Query. + * + * Matches documents that have fields that contain a term (not analyzed). + * + * The term query maps to Lucene TermQuery. + * + * @return \Elastica\Query\Builder + */ + public function term() + { + return $this->fieldOpen('term'); + } + + /** + * Close a 'term' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function termClose() + { + return $this->fieldClose(); + } + + /** + * Open a 'text_phrase' block. + * + * @return \Elastica\Query\Builder + */ + public function textPhrase() + { + return $this->fieldOpen('text_phrase'); + } + + /** + * Close a 'text_phrase' block. + * + * @return \Elastica\Query\Builder + */ + public function textPhraseClose() + { + return $this->close(); + } + + /** + * When using dis_max, the disjunction max tie breaker. + * + * @param float $multiplier Multiplier to use. + * + * @return \Elastica\Query\Builder + */ + public function tieBreakerMultiplier($multiplier) + { + return $this->field('tie_breaker_multiplier', (float) $multiplier); + } + + /** + * Query. + * + * @return \Elastica\Query\Builder + */ + public function wildcard() + { + return $this->fieldOpen('wildcard'); + } + + /** + * Close a 'wildcard' block. + * + * Alias of close() for ease of reading in source. + * + * @return \Elastica\Query\Builder + */ + public function wildcardClose() + { + return $this->fieldClose(); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Common.php b/vendor/ruflin/elastica/lib/Elastica/Query/Common.php new file mode 100644 index 00000000..6e112769 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Common.php @@ -0,0 +1,150 @@ +<?php + +namespace Elastica\Query; + + +/** + * Class Common + * @package Elastica + * @link http://www.elasticsearch.org/guide/reference/query-dsl/common-terms-query/ + */ +class Common extends AbstractQuery +{ + const OPERATOR_AND = 'and'; + const OPERATOR_OR = 'or'; + + /** + * @var string + */ + protected $_field; + + /** + * @var array + */ + protected $_queryParams = array(); + + /** + * @param string $field the field on which to query + * @param string $query the query string + * @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%) + */ + public function __construct($field, $query, $cutoffFrequency) + { + $this->setField($field); + $this->setQuery($query); + $this->setCutoffFrequency($cutoffFrequency); + } + + /** + * Set the field on which to query + * @param string $field the field on which to query + * @return \Elastica\Query\Common + */ + public function setField($field) + { + $this->_field = $field; + return $this; + } + + /** + * Set the query string for this query + * @param string $query + * @return \Elastica\Query\Common + */ + public function setQuery($query) + { + return $this->setQueryParam('query', $query); + } + + /** + * Set the frequency below which terms will be put in the low frequency group + * @param float $frequency percentage in decimal form (.001 == 0.1%) + * @return \Elastica\Query\Common + */ + public function setCutoffFrequency($frequency) + { + return $this->setQueryParam('cutoff_frequency', (float)$frequency); + } + + /** + * Set the logic operator for low frequency terms + * @param string $operator see OPERATOR_* class constants for options + * @return \Elastica\Query\Common + */ + public function setLowFrequencyOperator($operator) + { + return $this->setQueryParam('low_freq_operator', $operator); + } + + /** + * Set the logic operator for high frequency terms + * @param string $operator see OPERATOR_* class constants for options + * @return \Elastica\Query\Common + */ + public function setHighFrequencyOperator($operator) + { + return $this->setQueryParam('high_frequency_operator', $operator); + } + + /** + * Set the minimum_should_match parameter + * @param int|string $minimum minimum number of low frequency terms which must be present + * @return \Elastica\Query\Common + * @link Possible values for minimum_should_match http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html + */ + public function setMinimumShouldMatch($minimum) + { + return $this->setQueryParam('minimum_should_match', $minimum); + } + + /** + * Set the boost for this query + * @param float $boost + * @return \Elastica\Query\Common + */ + public function setBoost($boost) + { + return $this->setQueryParam('boost', (float)$boost); + } + + /** + * Set the analyzer for this query + * @param string $analyzer + * @return \Elastica\Query\Common + */ + public function setAnalyzer($analyzer) + { + return $this->setQueryParam('analyzer', $analyzer); + } + + /** + * Enable / disable computation of score factor based on the fraction of all query terms contained in the document + * @param bool $disable disable_coord is false by default + * @return \Elastica\Query\Common + */ + public function setDisableCoord($disable = true) + { + return $this->setQueryParam('disable_coord', (bool)$disable); + } + + /** + * Set a parameter in the body of this query + * @param string $key parameter key + * @param mixed $value parameter value + * @return \Elastica\Query\Common + */ + public function setQueryParam($key, $value) + { + $this->_queryParams[$key] = $value; + return $this; + } + + /** + * @return array + */ + public function toArray() + { + $this->setParam($this->_field, $this->_queryParams); + return parent::toArray(); + } +}
\ No newline at end of file diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/ConstantScore.php b/vendor/ruflin/elastica/lib/Elastica/Query/ConstantScore.php new file mode 100644 index 00000000..16854600 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/ConstantScore.php @@ -0,0 +1,68 @@ +<?php + +namespace Elastica\Query; +use Elastica\Filter\AbstractFilter; + +/** + * Constant score query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/constant-score-query.html + */ +class ConstantScore extends AbstractQuery +{ + /** + * Construct constant score query + * + * @param null|\Elastica\Filter\AbstractFilter|array $filter + */ + public function __construct($filter = null) + { + if (!is_null($filter)) { + $this->setFilter($filter); + } + } + + /** + * Set filter + * + * @param array|\Elastica\Filter\AbstractFilter $filter + * @return \Elastica\Query\ConstantScore Query object + */ + public function setFilter($filter) + { + if ($filter instanceof AbstractFilter) { + $filter = $filter->toArray(); + } + + return $this->setParam('filter', $filter); + } + + /** + * Set query + * + * @param array|\Elastica\Query\AbstractQuery $query + * @return \Elastica\Query\ConstantScore Query object + */ + public function setQuery($query) + { + if ($query instanceof AbstractQuery) { + $query = $query->toArray(); + } + + return $this->setParam('query', $query); + } + + /** + * Set boost + * + * @param float $boost + * @return \Elastica\Query\ConstantScore + */ + public function setBoost($boost) + { + return $this->setParam('boost', $boost); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/DisMax.php b/vendor/ruflin/elastica/lib/Elastica/Query/DisMax.php new file mode 100644 index 00000000..4b1d320d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/DisMax.php @@ -0,0 +1,59 @@ +<?php + +namespace Elastica\Query; +use Elastica\Exception\InvalidException; + +/** + * DisMax query + * + * @category Xodoa + * @package Elastica + * @author Hung Tran <oohnoitz@gmail.com> + * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html + */ +class DisMax extends AbstractQuery +{ + /** + * Adds a query to the current object + * + * @param \Elastica\Query\AbstractQuery|array $args Query + * @return \Elastica\Query\DisMax + * @throws \Elastica\Exception\InvalidException If not valid query + */ + public function addQuery($args) + { + if ($args instanceof AbstractQuery) { + $args = $args->toArray(); + } + + if (!is_array($args)) { + throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); + } + + return $this->addParam('queries', $args); + } + + /** + * Set boost + * + * @param float $boost + * @return \Elastica\Query\DisMax + */ + public function setBoost($boost) + { + return $this->setParam('boost', $boost); + } + + /** + * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields. + * + * If not set, defaults to 0.0 + * + * @param float $tieBreaker + * @return \Elastica\Query\DisMax + */ + public function setTieBreaker($tieBreaker = 0.0) + { + return $this->setParam('tie_breaker', $tieBreaker); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php b/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php new file mode 100644 index 00000000..c28d4cdd --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php @@ -0,0 +1,95 @@ +<?php + +namespace Elastica\Query; + +use Elastica\Filter\AbstractFilter; +use Elastica\Exception\InvalidException; + +/** + * Filtered query. Needs a query and a filter + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html + */ +class Filtered extends AbstractQuery +{ + /** + * Constructs a filtered query + * + * @param \Elastica\Query\AbstractQuery $query OPTIONAL Query object + * @param \Elastica\Filter\AbstractFilter $filter OPTIONAL Filter object + */ + public function __construct(AbstractQuery $query = null, AbstractFilter $filter = null) { + $this->setQuery($query); + $this->setFilter($filter); + } + + /** + * Sets a query + * + * @param \Elastica\Query\AbstractQuery $query Query object + * @return \Elastica\Query\Filtered Current object + */ + public function setQuery(AbstractQuery $query = null) + { + return $this->setParam('query', $query); + } + + /** + * Sets the filter + * + * @param \Elastica\Filter\AbstractFilter $filter Filter object + * @return \Elastica\Query\Filtered Current object + */ + public function setFilter(AbstractFilter $filter = null) + { + return $this->setParam('filter', $filter); + } + + /** + * Gets the filter. + * + * @return \Elastica\Filter\AbstractFilter + */ + public function getFilter() + { + return $this->getParam('filter'); + } + + /** + * Gets the query. + * + * @return \Elastica\Query\AbstractQuery + */ + public function getQuery() + { + return $this->getParam('query'); + } + + /** + * Converts query to array + * + * @return array Query array + * @see \Elastica\Query\AbstractQuery::toArray() + */ + public function toArray() + { + $filtered = array(); + + if ($this->hasParam('query') && $this->getParam('query') instanceof AbstractQuery) { + $filtered['query'] = $this->getParam('query')->toArray(); + } + + if ($this->hasParam('filter') && $this->getParam('filter') instanceof AbstractFilter) { + $filtered['filter'] = $this->getParam('filter')->toArray(); + } + + if (empty($filtered)) { + throw new InvalidException('A query and/or filter is required'); + } + + return array('filtered' => $filtered); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/FunctionScore.php b/vendor/ruflin/elastica/lib/Elastica/Query/FunctionScore.php new file mode 100644 index 00000000..8230c86e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/FunctionScore.php @@ -0,0 +1,201 @@ +<?php + +namespace Elastica\Query; +use Elastica\Filter\AbstractFilter; +use Elastica\Script; + +/** + * Class FunctionScore + * @package Elastica\Query + * @link http://www.elasticsearch.org/guide/reference/query-dsl/function-score-query/ + */ +class FunctionScore extends AbstractQuery +{ + const BOOST_MODE_MULTIPLY = 'multiply'; + const BOOST_MODE_REPLACE = 'replace'; + const BOOST_MODE_SUM = 'sum'; + const BOOST_MODE_AVERAGE = 'average'; + const BOOST_MODE_MAX = 'max'; + const BOOST_MODE_MIN = 'min'; + + const SCORE_MODE_MULTIPLY = 'multiply'; + const SCORE_MODE_SUM = 'sum'; + const SCORE_MODE_AVERAGE = 'avg'; + const SCORE_MODE_FIRST = 'first'; + const SCORE_MODE_MAX = 'max'; + const SCORE_MODE_MIN = 'min'; + + const DECAY_GAUSS = 'gauss'; + const DECAY_EXPONENTIAL = 'exp'; + const DECAY_LINEAR = 'linear'; + + protected $_functions = array(); + + /** + * Set the child query for this function_score query + * @param AbstractQuery $query + * @return \Elastica\Query\FunctionScore + */ + public function setQuery(AbstractQuery $query) + { + return $this->setParam('query', $query->toArray()); + } + + /** + * @param AbstractFilter $filter + * @return \Elastica\Param + */ + public function setFilter(AbstractFilter $filter) + { + return $this->setParam('filter', $filter->toArray()); + } + + /** + * Add a function to the function_score query + * @param string $functionType valid values are DECAY_* constants and script_score + * @param array|float $functionParams the body of the function. See documentation for proper syntax. + * @param AbstractFilter $filter optional filter to apply to the function + * @return \Elastica\Query\FunctionScore + */ + public function addFunction($functionType, $functionParams, AbstractFilter $filter = NULL) + { + $function = array( + $functionType => $functionParams + ); + if (!is_null($filter)) { + $function['filter'] = $filter->toArray(); + } + $this->_functions[] = $function; + return $this; + } + + /** + * Add a script_score function to the query + * @param Script $script a Script object + * @param AbstractFilter $filter an optional filter to apply to the function + * @return \Elastica\Query\FunctionScore + */ + public function addScriptScoreFunction(Script $script, AbstractFilter $filter = NULL) + { + return $this->addFunction('script_score', $script->toArray(), $filter); + } + + /** + * 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 $scaleWeight optional factor by which to multiply the score at the value provided by the $scale parameter + * @param AbstractFilter $filter a filter associated with this function + * @return \Elastica\Query\FunctionScore + */ + public function addDecayFunction($function, $field, $origin, $scale, $offset = NULL, $decay = NULL, $scaleWeight = NULL, + AbstractFilter $filter = NULL) + { + $functionParams = array( + $field => array( + 'origin' => $origin, + 'scale' => $scale + ) + ); + if (!is_null($offset)) { + $functionParams[$field]['offset'] = $offset; + } + if (!is_null($decay)) { + $functionParams[$field]['decay'] = (float)$decay; + } + if (!is_null($scaleWeight)) { + $functionParams[$field]['scale_weight'] = (float)$scaleWeight; + } + return $this->addFunction($function, $functionParams, $filter); + } + + /** + * Add a boost_factor function to the query + * @param float $boostFactor the boost factor value + * @param AbstractFilter $filter a filter associated with this function + */ + public function addBoostFactorFunction($boostFactor, AbstractFilter $filter = NULL) + { + $this->addFunction('boost_factor', $boostFactor, $filter); + } + + /** + * Add a random_score function to the query + * @param number $seed the seed value + * @param AbstractFilter $filter a filter associated with this function + * @param float $boost an optional boost value associated with this function + */ + public function addRandomScoreFunction($seed, AbstractFilter $filter = NULL, $boost = NULL) + { + $this->addFunction('random_score', array('seed' => $seed), $filter, $boost); + } + + /** + * Set an overall boost value for this query + * @param float $boost + * @return \Elastica\Query\FunctionScore + */ + public function setBoost($boost) + { + return $this->setParam('boost', (float)$boost); + } + + /** + * Restrict the combined boost of the function_score query and its child query + * @param float $maxBoost + * @return \Elastica\Query\FunctionScore + */ + public function setMaxBoost($maxBoost) + { + return $this->setParam('max_boost', (float)$maxBoost); + } + + /** + * The boost mode determines how the score of this query is combined with that of the child query + * @param string $mode see BOOST_MODE_* constants for valid options. Default is multiply. + * @return \Elastica\Query\FunctionScore + */ + public function setBoostMode($mode) + { + return $this->setParam('boost_mode', $mode); + } + + /** + * If set, this query will return results in random order. + * @param int $seed Set a seed value to return results in the same random order for consistent pagination. + * @return \Elastica\Query\FunctionScore + */ + public function setRandomScore($seed = NULL) + { + $seedParam = new \stdClass(); + if (!is_null($seed)) { + $seedParam->seed = $seed; + } + return $this->setParam('random_score', $seedParam); + } + + /** + * Set the score method + * @param string $mode see SCORE_MODE_* constants for valid options. Default is multiply. + * @return \Elastica\Query\FunctionScore + */ + public function setScoreMode($mode) + { + return $this->setParam('score_mode', $mode); + } + + /** + * @return array + */ + public function toArray() + { + if (sizeof($this->_functions)) { + $this->setParam('functions', $this->_functions); + } + return parent::toArray(); + } +}
\ No newline at end of file diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Fuzzy.php b/vendor/ruflin/elastica/lib/Elastica/Query/Fuzzy.php new file mode 100644 index 00000000..73b0f1a1 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Fuzzy.php @@ -0,0 +1,84 @@ +<?php + +namespace Elastica\Query; + +use Elastica\Exception\InvalidException; + +/** + * Fuzzy query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html + */ +class Fuzzy extends AbstractQuery +{ + /** + * Construct a fuzzy query + * + * @param string $fieldName Field name + * @param string $value String to search for + * @return \Elastica\Query\Fuzzy Current object + */ + public function __construct ($fieldName = null, $value = null) + { + if ($fieldName and $value) { + $this->setField($fieldName, $value); + } + } + + /** + * Set field for fuzzy query + * + * @param string $fieldName Field name + * @param string $value String to search for + * @return \Elastica\Query\Fuzzy Current object + */ + public function setField ($fieldName, $value) + { + if (!is_string($value) or !is_string($fieldName)) { + throw new InvalidException('The field and value arguments must be of type string.'); + } + if (count($this->getParams()) > 0 and array_shift(array_keys($this->getParams())) != $fieldName) { + throw new InvalidException('Fuzzy query can only support a single field.'); + } + return $this->setParam($fieldName, array('value' => $value)); + } + + /** + * Set optional parameters on the existing query + * + * @param string $param option name + * @param mixed $value Value of the parameter + * @return \Elastica\Query\Fuzzy Current object + */ + public function setFieldOption ($param, $value) { + //Retrieve the single existing field for alteration. + $params = $this->getParams(); + if (count($params) < 1) { + throw new InvalidException('No field has been set'); + } + $keyArray = array_keys($params); + $params[$keyArray[0]][$param] = $value; + + return $this->setparam($keyArray[0], $params[$keyArray[0]]); + } + + /** + * Deprecated method of setting a field. + * @deprecated + */ + public function addField($fieldName, $args) + { + if (!array_key_exists('value', $args)) { + throw new InvalidException('Fuzzy query can only support a single field.'); + } + $this->setField($fieldName, $args['value']); + unset($args['value']); + foreach ($args as $param => $value) { + $this->setFieldOption($param, $value); + } + return $this; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/FuzzyLikeThis.php b/vendor/ruflin/elastica/lib/Elastica/Query/FuzzyLikeThis.php new file mode 100644 index 00000000..ffa34a81 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/FuzzyLikeThis.php @@ -0,0 +1,215 @@ +<?php + +namespace Elastica\Query; + +/** + * Fuzzy Like This query + * + * @category Xodoa + * @package Elastica + * @author Raul Martinez, Jr <juneym@gmail.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/flt-query.html + */ +class FuzzyLikeThis extends AbstractQuery +{ + /** + * Field names + * + * @var array Field names + */ + protected $_fields = array(); + + /** + * Like text + * + * @var string Like text + */ + protected $_likeText = ''; + + /** + * Ignore term frequency + * + * @var boolean ignore term frequency + */ + protected $_ignoreTF = false; + + /** + * Max query terms value + * + * @var int Max query terms value + */ + protected $_maxQueryTerms = 25; + + /** + * minimum similarity + * + * @var int minimum similarity + */ + protected $_minSimilarity = 0.5; + + /** + * Prefix Length + * + * @var int Prefix Length + */ + protected $_prefixLength = 0; + + /** + * Boost + * + * @var float Boost + */ + protected $_boost = 1.0; + + /** + * Analyzer + * + * @var sting Analyzer + */ + protected $_analyzer; + + + /** + * Adds field to flt query + * + * @param array $fields Field names + * @return \Elastica\Query\FuzzyLikeThis Current object + */ + public function addFields(array $fields) + { + $this->_fields = $fields; + + return $this; + } + + /** + * Set the "like_text" value + * + * @param string $text + * @return \Elastica\Query\FuzzyLikeThis This current object + */ + public function setLikeText($text) + { + $text = trim($text); + $this->_likeText = $text; + + return $this; + } + + /** + * Set the "ignore_tf" value (ignore term frequency) + * + * @param bool $ignoreTF + * @return \Elastica\Query\FuzzyLikeThis Current object + */ + public function setIgnoreTF($ignoreTF) + { + $this->_ignoreTF = (bool) $ignoreTF; + + return $this; + } + + /** + * Set the minimum similarity + * + * @param int $value + * @return \Elastica\Query\FuzzyLikeThis This current object + */ + public function setMinSimilarity($value) + { + $value = (float) $value; + $this->_minSimilarity = $value; + + return $this; + } + + /** + * Set boost + * + * @param float $value Boost value + * @return \Elastica\Query\FuzzyLikeThis Query object + */ + public function setBoost($value) + { + $this->_boost = (float) $value; + + return $this; + } + + /** + * Set Prefix Length + * + * @param int $value Prefix length + * @return \Elastica\Query\FuzzyLikeThis + */ + public function setPrefixLength($value) + { + $this->_prefixLength = (int) $value; + + return $this; + } + + /** + * Set max_query_terms + * + * @param int $value Max query terms value + * @return \Elastica\Query\FuzzyLikeThis + */ + public function setMaxQueryTerms($value) + { + $this->_maxQueryTerms = (int) $value; + + return $this; + } + + /** + * Set analyzer + * + * @param string $text Analyzer text + * @return \Elastica\Query\FuzzyLikeThis + */ + public function setAnalyzer($text) + { + $text = trim($text); + $this->_analyzer = $text; + + return $this; + } + + /** + * Converts fuzzy like this query to array + * + * @return array Query array + * @see \Elastica\Query\AbstractQuery::toArray() + */ + public function toArray() + { + if (!empty($this->_fields)) { + $args['fields'] = $this->_fields; + } + + if (!empty($this->_boost)) { + $args['boost'] = $this->_boost; + } + + if (!empty($this->_likeText)) { + $args['like_text'] = $this->_likeText; + } + + if (!empty($this->_analyzer)) { + $args['analyzer'] = $this->_analyzer; + } + + + $args['min_similarity'] = ($this->_minSimilarity > 0) ? $this->_minSimilarity : 0; + + $args['prefix_length'] = $this->_prefixLength; + $args['ignore_tf'] = $this->_ignoreTF; + $args['max_query_terms'] = $this->_maxQueryTerms; + + $data = parent::toArray(); + $args = array_merge($args, $data['fuzzy_like_this']); + + return array('fuzzy_like_this' => $args); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/HasChild.php b/vendor/ruflin/elastica/lib/Elastica/Query/HasChild.php new file mode 100644 index 00000000..e849a9bf --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/HasChild.php @@ -0,0 +1,63 @@ +<?php + +namespace Elastica\Query; +use Elastica\Query as BaseQuery; + +/** + * Returns parent documents having child docs matching the query + * + * @category Xodoa + * @package Elastica + * @author Fabian Vogler <fabian@equivalence.ch> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query.html + */ +class HasChild extends AbstractQuery +{ + /** + * Construct HasChild Query + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @param string $type Parent document type + */ + public function __construct($query, $type = null) + { + $this->setType($type); + $this->setQuery($query); + } + + /** + * Sets query object + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @return \Elastica\Query\HasChild + */ + public function setQuery($query) + { + $query = BaseQuery::create($query); + $data = $query->toArray(); + + return $this->setParam('query', $data['query']); + } + + /** + * Set type of the parent document + * + * @param string $type Parent document type + * @return \Elastica\Query\HasChild Current object + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Sets the scope + * + * @param string $scope Scope + * @return \Elastica\Query\HasChild Current object + */ + public function setScope($scope) + { + return $this->setParam('_scope', $scope); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/HasParent.php b/vendor/ruflin/elastica/lib/Elastica/Query/HasParent.php new file mode 100644 index 00000000..809fb18d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/HasParent.php @@ -0,0 +1,62 @@ +<?php + +namespace Elastica\Query; +use Elastica\Query as BaseQuery; + +/** + * Returns child documents having parent docs matching the query + * + * @category Xodoa + * @package Elastica + * @link http://www.elasticsearch.org/guide/reference/query-dsl/has-parent-query.html + */ +class HasParent extends AbstractQuery +{ + /** + * Construct HasChild Query + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @param string $type Parent document type + */ + public function __construct($query, $type) + { + $this->setQuery($query); + $this->setType($type); + } + + /** + * Sets query object + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @return \Elastica\Filter\HasParent + */ + public function setQuery($query) + { + $query = BaseQuery::create($query); + $data = $query->toArray(); + + return $this->setParam('query', $data['query']); + } + + /** + * Set type of the parent document + * + * @param string $type Parent document type + * @return \Elastica\Filter\HasParent Current object + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Sets the scope + * + * @param string $scope Scope + * @return \Elastica\Filter\HasParent Current object + */ + public function setScope($scope) + { + return $this->setParam('_scope', $scope); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Ids.php b/vendor/ruflin/elastica/lib/Elastica/Query/Ids.php new file mode 100644 index 00000000..f4a6f1aa --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Ids.php @@ -0,0 +1,117 @@ +<?php + +namespace Elastica\Query; +use Elastica\Type; + +/** + * Ids Query + * + * @category Xodoa + * @package Elastica + * @author Lee Parker + * @author Nicolas Ruflin <spam@ruflin.com> + * @author Tim Rupp + * @link http://www.elasticsearch.org/guide/reference/query-dsl/ids-query.html + */ +class Ids extends AbstractQuery +{ + /** + * Params + * + * @var array Params + */ + protected $_params = array(); + + /** + * Creates filter object + * + * @param string|\Elastica\Type $type Type to filter on + * @param array $ids List of ids + */ + public function __construct($type = null, array $ids = array()) + { + $this->setType($type); + $this->setIds($ids); + } + + /** + * Adds one more filter to the and filter + * + * @param string $id Adds id to filter + * @return \Elastica\Query\Ids Current object + */ + public function addId($id) + { + $this->_params['values'][] = $id; + + return $this; + } + + /** + * Adds one more type to query + * + * @param string|\Elastica\Type $type Type name or object + * @return \Elastica\Query\Ids Current object + */ + public function addType($type) + { + if ($type instanceof Type) { + $type = $type->getName(); + } elseif (empty($type) && !is_numeric($type)) { + // A type can be 0, but cannot be empty + return $this; + } + + $this->_params['type'][] = $type; + + return $this; + } + + /** + * Set type + * + * @param string|\Elastica\Type $type Type name or object + * @return \Elastica\Query\Ids Current object + */ + public function setType($type) + { + if ($type instanceof Type) { + $type = $type->getName(); + } elseif (empty($type) && !is_numeric($type)) { + // A type can be 0, but cannot be empty + return $this; + } + + $this->_params['type'] = $type; + + return $this; + } + + /** + * Sets the ids to filter + * + * @param array|string $ids List of ids + * @return \Elastica\Query\Ids Current object + */ + public function setIds($ids) + { + if (is_array($ids)) { + $this->_params['values'] = $ids; + } else { + $this->_params['values'] = array($ids); + } + + return $this; + } + + /** + * Converts filter to array + * + * @see \Elastica\Query\AbstractQuery::toArray() + * @return array Query array + */ + public function toArray() + { + return array('ids' => $this->_params); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Match.php b/vendor/ruflin/elastica/lib/Elastica/Query/Match.php new file mode 100644 index 00000000..ba66ad63 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Match.php @@ -0,0 +1,198 @@ +<?php + +namespace Elastica\Query; + +/** + * Match query + * + * @category Xodoa + * @package Elastica + * @author F21 + * @author WONG Wing Lun <luiges90@gmail.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html + */ +class Match extends AbstractQuery +{ + const ZERO_TERM_NONE = 'none'; + const ZERO_TERM_ALL = 'all'; + + /** + * Sets a param for the message array + * + * @param string $field + * @param mixed $values + * @return \Elastica\Query\Match + */ + public function setField($field, $values) + { + return $this->setParam($field, $values); + } + + /** + * Sets a param for the given field + * + * @param string $field + * @param string $key + * @param string $value + * @return \Elastica\Query\Match + */ + public function setFieldParam($field, $key, $value) + { + if (!isset($this->_params[$field])) { + $this->_params[$field] = array(); + } + + $this->_params[$field][$key] = $value; + + return $this; + } + + /** + * Sets the query string + * + * @param string $field + * @param string $query + * @return \Elastica\Query\Match + */ + public function setFieldQuery($field, $query) + { + return $this->setFieldParam($field, 'query', $query); + } + + /** + * Set field type + * + * @param string $field + * @param string $type + * @return \Elastica\Query\Match + */ + public function setFieldType($field, $type) + { + return $this->setFieldParam($field, 'type', $type); + } + + /** + * Set field operator + * + * @param string $field + * @param string $operator + * @return \Elastica\Query\Match + */ + public function setFieldOperator($field, $operator) + { + return $this->setFieldParam($field, 'operator', $operator); + } + + /** + * Set field analyzer + * + * @param string $field + * @param string $analyzer + * @return \Elastica\Query\Match + */ + public function setFieldAnalyzer($field, $analyzer) + { + return $this->setFieldParam($field, 'analyzer', $analyzer); + } + + /** + * Set field boost value + * + * If not set, defaults to 1.0. + * + * @param string $field + * @param float $boost + * @return \Elastica\Query\Match + */ + public function setFieldBoost($field, $boost = 1.0) + { + return $this->setFieldParam($field, 'boost', (float) $boost); + } + + /** + * Set field minimum should match + * + * @param string $field + * @param int|string $minimumShouldMatch + * @return \Elastica\Query\Match + * @link Possible values for minimum_should_match http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html + */ + public function setFieldMinimumShouldMatch($field, $minimumShouldMatch) + { + return $this->setFieldParam($field, 'minimum_should_match', $minimumShouldMatch); + } + + /** + * Set field fuzziness + * + * @param string $field + * @param mixed $fuzziness + * @return \Elastica\Query\Match + */ + public function setFieldFuzziness($field, $fuzziness) + { + return $this->setFieldParam($field, 'fuzziness', $fuzziness); + } + + /** + * Set field fuzzy rewrite + * + * @param string $field + * @param string $fuzzyRewrite + * @return \Elastica\Query\Match + */ + public function setFieldFuzzyRewrite($field, $fuzzyRewrite) + { + return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite); + } + + /** + * Set field prefix length + * + * @param string $field + * @param int $prefixLength + * @return \Elastica\Query\Match + */ + public function setFieldPrefixLength($field, $prefixLength) + { + return $this->setFieldParam($field, 'prefix_length', (int) $prefixLength); + } + + /** + * Set field max expansions + * + * @param string $field + * @param int $maxExpansions + * @return \Elastica\Query\Match + */ + public function setFieldMaxExpansions($field, $maxExpansions) + { + return $this->setFieldParam($field, 'max_expansions', (int) $maxExpansions); + } + + /** + * Set zero terms query + * + * If not set, default to 'none' + * + * @param string $field + * @param string $zeroTermQuery + * @return \Elastica\Query\Match + */ + public function setFieldZeroTermsQuery($field, $zeroTermQuery = 'none') + { + return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery); + } + + /** + * Set cutoff frequency + * + * @param string $field + * @param float $cutoffFrequency + * @return \Elastica\Query\Match + */ + public function setFieldCutoffFrequency($field, $cutoffFrequency) + { + return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/MatchAll.php b/vendor/ruflin/elastica/lib/Elastica/Query/MatchAll.php new file mode 100644 index 00000000..23b4fdfc --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MatchAll.php @@ -0,0 +1,22 @@ +<?php + +namespace Elastica\Query; + +/** + * Match all query. Returns all results + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/match-all-query.html + */ +class MatchAll extends AbstractQuery +{ + /** + * Creates match all query + */ + public function __construct() + { + $this->_params = new \stdClass(); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/MoreLikeThis.php b/vendor/ruflin/elastica/lib/Elastica/Query/MoreLikeThis.php new file mode 100644 index 00000000..d9ae4284 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MoreLikeThis.php @@ -0,0 +1,162 @@ +<?php + +namespace Elastica\Query; + +/** + * More Like This query + * + * @category Xodoa + * @package Elastica + * @author Raul Martinez, Jr <juneym@gmail.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html + */ +class MoreLikeThis extends AbstractQuery +{ + /** + * Adds field to mlt query + * + * @param array $fields Field names + * @return \Elastica\Query\MoreLikeThis Current object + */ + public function setFields(array $fields) + { + return $this->setParam('fields', $fields); + } + + /** + * Set the "like_text" value + * + * @param string $likeText + * @return \Elastica\Query\MoreLikeThis This current object + */ + public function setLikeText($likeText) + { + $likeText = trim($likeText); + + return $this->setParam('like_text', $likeText); + } + + /** + * Set boost + * + * @param float $boost Boost value + * @return \Elastica\Query\MoreLikeThis Query object + */ + public function setBoost($boost) + { + return $this->setParam('boost', (float) $boost); + } + + /** + * Set max_query_terms + * + * @param int $maxQueryTerms Max query terms value + * @return \Elastica\Query\MoreLikeThis + */ + public function setMaxQueryTerms($maxQueryTerms) + { + return $this->setParam('max_query_terms', (int) $maxQueryTerms); + } + + /** + * Set percent terms to match + * + * @param float $percentTermsToMatch Percentage + * @return \Elastica\Query\MoreLikeThis + */ + public function setPercentTermsToMatch($percentTermsToMatch) + { + return $this->setParam('percent_terms_to_match', (float) $percentTermsToMatch); + } + + /** + * Set min term frequency + * + * @param int $minTermFreq + * @return \Elastica\Query\MoreLikeThis + */ + public function setMinTermFrequency($minTermFreq) + { + return $this->setParam('min_term_freq', (int) $minTermFreq); + } + + /** + * set min document frequency + * + * @param int $minDocFreq + * @return \Elastica\Query\MoreLikeThis + */ + public function setMinDocFrequency($minDocFreq) + { + return $this->setParam('min_doc_freq', (int) $minDocFreq); + } + + /** + * set max document frequency + * + * @param int $maxDocFreq + * @return \Elastica\Query\MoreLikeThis + */ + public function setMaxDocFrequency($maxDocFreq) + { + return $this->setParam('max_doc_freq', (int) $maxDocFreq); + } + + /** + * Set min word length + * + * @param int $minWordLength + * @return \Elastica\Query\MoreLikeThis + */ + public function setMinWordLength($minWordLength) + { + return $this->setParam('min_word_length', (int) $minWordLength); + } + + /** + * Set max word length + * + * @param int $maxWordLength + * @return \Elastica\Query\MoreLikeThis + */ + public function setMaxWordLength($maxWordLength) + { + return $this->setParam('max_word_length', (int) $maxWordLength); + } + + /** + * Set boost terms + * + * @param bool $boostTerms + * @return \Elastica\Query\MoreLikeThis + * @link http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html + */ + public function setBoostTerms($boostTerms) + { + return $this->setParam('boost_terms', (bool) $boostTerms); + } + + /** + * Set analyzer + * + * @param string $analyzer + * @return \Elastica\Query\MoreLikeThis + */ + public function setAnalyzer($analyzer) + { + $analyzer = trim($analyzer); + + return $this->setParam('analyzer', $analyzer); + } + + /** + * Set stop words + * + * @param array $stopWords + * @return \Elastica\Query\MoreLikeThis + */ + public function setStopWords(array $stopWords) + { + return $this->setParam('stop_words', $stopWords); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/MultiMatch.php b/vendor/ruflin/elastica/lib/Elastica/Query/MultiMatch.php new file mode 100644 index 00000000..ac2d01b3 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MultiMatch.php @@ -0,0 +1,180 @@ +<?php + +namespace Elastica\Query; + +/** + * Multi Match + * + * @category Xodoa + * @package Elastica + * @author Rodolfo Adhenawer Campagnoli Moraes <adhenawer@gmail.com> + * @author Wong Wing Lun <luiges90@gmail.com> + * @author Tristan Maindron <tmaindron@gmail.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query.html + */ +class MultiMatch extends AbstractQuery +{ + const TYPE_BEST_FIELDS = 'best_fields'; + const TYPE_MOST_FIELDS = 'most_fields'; + const TYPE_CROSS_FIELDS = 'cross_fields'; + const TYPE_PHRASE = 'phrase'; + const TYPE_PHRASE_PREFIX = 'phrase_prefix'; + + const OPERATOR_OR = 'or'; + const OPERATOR_AND = 'and'; + + const ZERO_TERM_NONE = 'none'; + const ZERO_TERM_ALL = 'all'; + + /** + * Sets the query + * + * @param string $query Query + * @return \Elastica\Query\MultiMatch Current object + */ + public function setQuery($query = '') + { + return $this->setParam('query', $query); + } + + /** + * Sets Fields to be used in the query. + * + * @param array $fields Fields + * @return \Elastica\Query\MultiMatch Current object + */ + public function setFields($fields = array()) + { + return $this->setParam('fields', $fields); + } + + /** + * Sets use dis max indicating to either create a dis_max query or a bool query. + * + * If not set, defaults to true. + * + * @param boolean $useDisMax + * @return \Elastica\Query\MultiMatch Current object + */ + public function setUseDisMax($useDisMax = true) + { + return $this->setParam('use_dis_max', $useDisMax); + } + + /** + * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields. + * + * If not set, defaults to 0.0. + * + * @param float $tieBreaker + * @return \Elastica\Query\MultiMatch Current object + */ + public function setTieBreaker($tieBreaker = 0.0) + { + return $this->setParam('tie_breaker', $tieBreaker); + } + + /** + * Sets operator for Match Query + * + * If not set, defaults to 'or' + * + * @param string $operator + * @return \Elastica\Query\MultiMatch Current object + */ + public function setOperator($operator = 'or') + { + return $this->setParam('operator', $operator); + } + + /** + * Set field minimum should match for Match Query + * + * @param int $minimumShouldMatch + * @return \Elastica\Query\Match + */ + public function setMinimumShouldMatch($minimumShouldMatch) + { + return $this->setParam('minimum_should_match', (int) $minimumShouldMatch); + } + + /** + * Set zero terms query for Match Query + * + * If not set, default to 'none' + * + * @param string $zeroTermQuery + * @return \Elastica\Query\Match + */ + public function setZeroTermsQuery($zeroTermQuery = 'none') + { + return $this->setParam('zero_terms_query', $zeroTermQuery); + } + + /** + * Set cutoff frequency for Match Query + * + * @param float $cutoffFrequency + * @return \Elastica\Query\Match + */ + public function setCutoffFrequency($cutoffFrequency) + { + return $this->setParam('cutoff_frequency', $cutoffFrequency); + } + + /** + * Set type + * + * @param string $field + * @param string $type + * @return \Elastica\Query\Match + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Set fuzziness + * + * @param float $fuzziness + * @return \Elastica\Query\Match + */ + public function setFuzziness($fuzziness) + { + return $this->setParam('fuzziness', (float) $fuzziness); + } + + /** + * Set prefix length + * + * @param int $prefixLength + * @return \Elastica\Query\Match + */ + public function setPrefixLength($prefixLength) + { + return $this->setParam('prefix_length', (int) $prefixLength); + } + + /** + * Set max expansions + * + * @param int $maxExpansions + * @return \Elastica\Query\Match + */ + public function setMaxExpansions($maxExpansions) + { + return $this->setParam('max_expansions', (int) $maxExpansions); + } + + /** + * Set analyzer + * + * @param string $analyzer + * @return \Elastica\Query\Match + */ + public function setAnalyzer($analyzer) + { + return $this->setParam('analyzer', $analyzer); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Nested.php b/vendor/ruflin/elastica/lib/Elastica/Query/Nested.php new file mode 100644 index 00000000..3d2f2f64 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Nested.php @@ -0,0 +1,47 @@ +<?php + +namespace Elastica\Query; + +/** + * Nested query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html + */ +class Nested extends AbstractQuery +{ + /** + * Adds field to mlt query + * + * @param string $path Nested object path + * @return \Elastica\Query\Nested + */ + public function setPath($path) + { + return $this->setParam('path', $path); + } + + /** + * Sets nested query + * + * @param \Elastica\Query\AbstractQuery $query + * @return \Elastica\Query\Nested + */ + public function setQuery(AbstractQuery $query) + { + return $this->setParam('query', $query->toArray()); + } + + /** + * Set score method + * + * @param string $scoreMode Options: avg, total, max and none. + * @return \Elastica\Query\Nested + */ + public function setScoreMode($scoreMode) + { + return $this->setParam('score_mode', $scoreMode); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Prefix.php b/vendor/ruflin/elastica/lib/Elastica/Query/Prefix.php new file mode 100644 index 00000000..4306fd9c --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Prefix.php @@ -0,0 +1,48 @@ +<?php + +namespace Elastica\Query; + +/** + * Prefix query + * + * @category Xodoa + * @package Elastica + * @link http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html + */ +class Prefix extends AbstractQuery +{ + /** + * Constructs the Prefix query object + * + * @param array $prefix OPTIONAL Calls setRawPrefix with the given $prefix array + */ + public function __construct(array $prefix = array()) + { + $this->setRawPrefix($prefix); + } + + /** + * setRawPrefix can be used instead of setPrefix if some more special + * values for a prefix have to be set. + * + * @param array $prefix Prefix array + * @return \Elastica\Query\Prefix Current object + */ + public function setRawPrefix(array $prefix) + { + return $this->setParams($prefix); + } + + /** + * Adds a prefix to the prefix query + * + * @param string $key Key to query + * @param string|array $value Values(s) for the query. Boost can be set with array + * @param float $boost OPTIONAL Boost value (default = 1.0) + * @return \Elastica\Query\Prefix Current object + */ + public function setPrefix($key, $value, $boost = 1.0) + { + return $this->setRawPrefix(array($key => array('value' => $value, 'boost' => $boost))); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/QueryString.php b/vendor/ruflin/elastica/lib/Elastica/Query/QueryString.php new file mode 100644 index 00000000..7d0b0094 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/QueryString.php @@ -0,0 +1,267 @@ +<?php + +namespace Elastica\Query; +use Elastica\Exception\InvalidException; + +/** + * QueryString query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com>, Jasper van Wanrooy <jasper@vanwanrooy.net> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html + */ +class QueryString extends AbstractQuery +{ + /** + * Query string + * + * @var string Query string + */ + protected $_queryString = ''; + + /** + * Creates query string object. Calls setQuery with argument + * + * @param string $queryString OPTIONAL Query string for object + */ + public function __construct($queryString = '') + { + $this->setQuery($queryString); + } + + /** + * Sets a new query string for the object + * + * @param string $query Query string + * @throws \Elastica\Exception\InvalidException + * @return \Elastica\Query\QueryString Current object + */ + public function setQuery($query = '') + { + if (!is_string($query)) { + throw new InvalidException('Parameter has to be a string'); + } + + return $this->setParam('query', $query); + } + + /** + * Sets the default field + * + * If no field is set, _all is chosen + * + * @param string $field Field + * @return \Elastica\Query\QueryString Current object + */ + public function setDefaultField($field) + { + return $this->setParam('default_field', $field); + } + + /** + * Sets the default operator AND or OR + * + * If no operator is set, OR is chosen + * + * @param string $operator Operator + * @return \Elastica\Query\QueryString Current object + */ + public function setDefaultOperator($operator) + { + return $this->setParam('default_operator', $operator); + } + + /** + * Sets the analyzer to analyze the query with. + * + * @param string $analyzer Analyser to use + * @return \Elastica\Query\QueryString Current object + */ + public function setAnalyzer($analyzer) + { + return $this->setParam('analyzer', $analyzer); + } + + /** + * Sets the parameter to allow * and ? as first characters. + * + * If not set, defaults to true. + * + * @param bool $allow + * @return \Elastica\Query\QueryString Current object + */ + public function setAllowLeadingWildcard($allow = true) + { + return $this->setParam('allow_leading_wildcard', (bool) $allow); + } + + /** + * Sets the parameter to auto-lowercase terms of some queries. + * + * If not set, defaults to true. + * + * @param bool $lowercase + * @return \Elastica\Query\QueryString Current object + */ + public function setLowercaseExpandedTerms($lowercase = true) + { + return $this->setParam('lowercase_expanded_terms', (bool) $lowercase); + } + + /** + * Sets the parameter to enable the position increments in result queries. + * + * If not set, defaults to true. + * + * @param bool $enabled + * @return \Elastica\Query\QueryString Current object + */ + public function setEnablePositionIncrements($enabled = true) + { + return $this->setParam('enable_position_increments', (bool) $enabled); + } + + /** + * Sets the fuzzy prefix length parameter. + * + * If not set, defaults to 0. + * + * @param int $length + * @return \Elastica\Query\QueryString Current object + */ + public function setFuzzyPrefixLength($length = 0) + { + return $this->setParam('fuzzy_prefix_length', (int) $length); + } + + /** + * Sets the fuzzy minimal similarity parameter. + * + * If not set, defaults to 0.5 + * + * @param float $minSim + * @return \Elastica\Query\QueryString Current object + */ + public function setFuzzyMinSim($minSim = 0.5) + { + return $this->setParam('fuzzy_min_sim', (float) $minSim); + } + + /** + * Sets the phrase slop. + * + * If zero, exact phrases are required. + * If not set, defaults to zero. + * + * @param int $phraseSlop + * @return \Elastica\Query\QueryString Current object + */ + public function setPhraseSlop($phraseSlop = 0) + { + return $this->setParam('phrase_slop', (int) $phraseSlop); + } + + /** + * Sets the boost value of the query. + * + * If not set, defaults to 1.0. + * + * @param float $boost + * @return \Elastica\Query\QueryString Current object + */ + public function setBoost($boost = 1.0) + { + return $this->setParam('boost', (float) $boost); + } + + /** + * Allows analyzing of wildcard terms. + * + * If not set, defaults to true + * + * @param bool $analyze + * @return \Elastica\Query\QueryString Current object + */ + public function setAnalyzeWildcard($analyze = true) + { + return $this->setParam('analyze_wildcard', (bool) $analyze); + } + + /** + * Sets the param to automatically generate phrase queries. + * + * If not set, defaults to true. + * + * @param bool $autoGenerate + * @return \Elastica\Query\QueryString Current object + */ + public function setAutoGeneratePhraseQueries($autoGenerate = true) + { + return $this->setParam('auto_generate_phrase_queries', (bool) $autoGenerate); + } + + /** + * Sets the fields + * + * If no fields are set, _all is chosen + * + * @param array $fields Fields + * @throws \Elastica\Exception\InvalidException + * @return \Elastica\Query\QueryString Current object + */ + public function setFields(array $fields) + { + if (!is_array($fields)) { + throw new InvalidException('Parameter has to be an array'); + } + + return $this->setParam('fields', $fields); + } + + /** + * Whether to use bool or dis_max queries to internally combine results for multi field search. + * + * @param bool $value Determines whether to use + * @return \Elastica\Query\QueryString Current object + */ + public function setUseDisMax($value = true) + { + return $this->setParam('use_dis_max', (bool) $value); + } + + /** + * When using dis_max, the disjunction max tie breaker. + * + * If not set, defaults to 0. + * + * @param int $tieBreaker + * @return \Elastica\Query\QueryString Current object + */ + public function setTieBreaker($tieBreaker = 0) + { + return $this->setParam('tie_breaker', (float) $tieBreaker); + } + + /** + * Set a re-write condition. See https://github.com/elasticsearch/elasticsearch/issues/1186 for additional information + * + * @param string $rewrite + * @return \Elastica\Query\QueryString Current object + */ + public function setRewrite($rewrite = "") + { + return $this->setParam('rewrite', $rewrite); + } + + /** + * Converts query to array + * + * @see \Elastica\Query\AbstractQuery::toArray() + * @return array Query array + */ + public function toArray() + { + return array('query_string' => array_merge(array('query' => $this->_queryString), $this->getParams()),); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Range.php b/vendor/ruflin/elastica/lib/Elastica/Query/Range.php new file mode 100644 index 00000000..54b79027 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Range.php @@ -0,0 +1,39 @@ +<?php + +namespace Elastica\Query; + +/** + * Range query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/range-query.html + */ +class Range extends AbstractQuery +{ + /** + * Constructor + * + * @param string $fieldName Field name + * @param array $args Field arguments + */ + public function __construct($fieldName = null, array $args = array()) + { + if ($fieldName) { + $this->addField($fieldName, $args); + } + } + + /** + * Adds a range field to the query + * + * @param string $fieldName Field name + * @param array $args Field arguments + * @return \Elastica\Query\Range Current object + */ + public function addField($fieldName, array $args) + { + return $this->setParam($fieldName, $args); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Simple.php b/vendor/ruflin/elastica/lib/Elastica/Query/Simple.php new file mode 100644 index 00000000..2448ca79 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Simple.php @@ -0,0 +1,55 @@ +<?php + +namespace Elastica\Query; + +/** + * Simple query + * Pure php array query. Can be used to create any not existing type of query. + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + */ +class Simple extends AbstractQuery +{ + /** + * Query + * + * @var array Query + */ + protected $_query = array(); + + /** + * Constructs a query based on an array + * + * @param array $query Query array + */ + public function __construct(array $query) + { + $this->setQuery($query); + } + + /** + * Sets new query array + * + * @param array $query Query array + * @return \Elastica\Query\Simple Current object + */ + public function setQuery(array $query) + { + $this->_query = $query; + + return $this; + } + + /** + * Converts query to array + * + * @return array Query array + * @see \Elastica\Query\AbstractQuery::toArray() + */ + public function toArray() + { + return $this->_query; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php b/vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php new file mode 100644 index 00000000..a6c4ba9d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php @@ -0,0 +1,65 @@ +<?php + +namespace Elastica\Query; + +/** + * Class SimpleQueryString + * @package Elastica\Query + * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html + */ +class SimpleQueryString extends AbstractQuery +{ + const OPERATOR_AND = "and"; + const OPERATOR_OR = "or"; + + /** + * @param string $query + * @param array $fields + */ + public function __construct($query, array $fields = array()) + { + $this->setQuery($query); + if (sizeof($fields)) { + $this->setFields($fields); + } + } + + /** + * Set the querystring for this query + * @param string $query see ES documentation for querystring syntax + * @return \Elastica\Query\SimpleQueryString + */ + public function setQuery($query) + { + return $this->setParam("query", $query); + } + + /** + * @param string[] $fields the fields on which to perform this query. Defaults to index.query.default_field. + * @return \Elastica\Query\SimpleQueryString + */ + public function setFields(array $fields) + { + return $this->setParam("fields", $fields); + } + + /** + * Set the default operator to use if no explicit operator is defined in the query string + * @param string $operator see OPERATOR_* constants for options + * @return \Elastica\Query\SimpleQueryString + */ + public function setDefaultOperator($operator) + { + return $this->setParam("default_operator", $operator); + } + + /** + * Set the analyzer used to analyze each term of the query + * @param string $analyzer + * @return \Elastica\Query\SimpleQueryString + */ + public function setAnalyzer($analyzer) + { + return $this->setParam("analyzer", $analyzer); + } +}
\ No newline at end of file diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Term.php b/vendor/ruflin/elastica/lib/Elastica/Query/Term.php new file mode 100644 index 00000000..eb20eb86 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Term.php @@ -0,0 +1,49 @@ +<?php + +namespace Elastica\Query; + +/** + * Term query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html + */ +class Term extends AbstractQuery +{ + /** + * Constructs the Term query object + * + * @param array $term OPTIONAL Calls setTerm with the given $term array + */ + public function __construct(array $term = array()) + { + $this->setRawTerm($term); + } + + /** + * Set term can be used instead of addTerm if some more special + * values for a term have to be set. + * + * @param array $term Term array + * @return \Elastica\Query\Term Current object + */ + public function setRawTerm(array $term) + { + return $this->setParams($term); + } + + /** + * Adds a term to the term query + * + * @param string $key Key to query + * @param string|array $value Values(s) for the query. Boost can be set with array + * @param float $boost OPTIONAL Boost value (default = 1.0) + * @return \Elastica\Query\Term Current object + */ + public function setTerm($key, $value, $boost = 1.0) + { + return $this->setRawTerm(array($key => array('value' => $value, 'boost' => $boost))); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Terms.php b/vendor/ruflin/elastica/lib/Elastica/Query/Terms.php new file mode 100644 index 00000000..41cc9216 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Terms.php @@ -0,0 +1,103 @@ +<?php + +namespace Elastica\Query; +use Elastica\Exception\InvalidException; + +/** + * Terms query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/terms-query.html + */ +class Terms extends AbstractQuery +{ + /** + * Terms + * + * @var array Terms + */ + protected $_terms = array(); + + /** + * Params + * + * @var array Params + */ + protected $_params = array(); + + /** + * Terms key + * + * @var string Terms key + */ + protected $_key = ''; + + /** + * Construct terms query + * + * @param string $key OPTIONAL Terms key + * @param array $terms OPTIONAL Terms list + */ + public function __construct($key = '', array $terms = array()) + { + $this->setTerms($key, $terms); + } + + /** + * Sets key and terms for the query + * + * @param string $key Terms key + * @param array $terms Terms for the query. + * @return \Elastica\Query\Terms + */ + public function setTerms($key, array $terms) + { + $this->_key = $key; + $this->_terms = array_values($terms); + + return $this; + } + + /** + * Adds a single term to the list + * + * @param string $term Term + * @return \Elastica\Query\Terms + */ + public function addTerm($term) + { + $this->_terms[] = $term; + + return $this; + } + + /** + * Sets the minimum matching values + * + * @param int $minimum Minimum value + * @return \Elastica\Query\Terms + */ + public function setMinimumMatch($minimum) + { + return $this->setParam('minimum_match', (int) $minimum); + } + + /** + * Converts the terms object to an array + * + * @see \Elastica\Query\AbstractQuery::toArray() + * @throws \Elastica\Exception\InvalidException + * @return array Query array + */ + public function toArray() + { + if (empty($this->_key)) { + throw new InvalidException('Terms key has to be set'); + } + $this->setParam($this->_key, $this->_terms); + + return parent::toArray(); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/TopChildren.php b/vendor/ruflin/elastica/lib/Elastica/Query/TopChildren.php new file mode 100644 index 00000000..baaf7501 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/TopChildren.php @@ -0,0 +1,52 @@ +<?php + +namespace Elastica\Query; +use Elastica\Query as BaseQuery; + +/** + * Runs the child query with an estimated hits size, and out of the hit docs, aggregates it into parent docs. + * + * @category Xodoa + * @package Elastica + * @author Wu Yang <darkyoung@gmail.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/top-children-query.html + */ +class TopChildren extends AbstractQuery +{ + /** + * Construct topChildren query + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @param string $type Parent document type + */ + public function __construct($query, $type = null) + { + $this->setQuery($query); + $this->setType($type); + } + + /** + * Sets query object + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * @return \Elastica\Query\TopChildren + */ + public function setQuery($query) + { + $query = BaseQuery::create($query); + $data = $query->toArray(); + + return $this->setParam('query', $data['query']); + } + + /** + * Set type of the parent document + * + * @param string $type Parent document type + * @return \Elastica\Query\TopChildren Current object + */ + public function setType($type) + { + return $this->setParam('type', $type); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Wildcard.php b/vendor/ruflin/elastica/lib/Elastica/Query/Wildcard.php new file mode 100644 index 00000000..68aca67e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Wildcard.php @@ -0,0 +1,41 @@ +<?php + +namespace Elastica\Query; + +/** + * Wildcard query + * + * @category Xodoa + * @package Elastica + * @author Nicolas Ruflin <spam@ruflin.com> + * @link http://www.elasticsearch.org/guide/reference/query-dsl/wildcard-query.html + */ +class Wildcard extends AbstractQuery +{ + /** + * Construct wildcard query + * + * @param string $key OPTIONAL Wildcard key + * @param string $value OPTIONAL Wildcard value + * @param float $boost OPTIONAL Boost value (default = 1) + */ + public function __construct($key = '', $value = null, $boost = 1.0) + { + if (!empty($key)) { + $this->setValue($key, $value, $boost); + } + } + + /** + * Sets the query expression for a key with its boost value + * + * @param string $key + * @param string $value + * @param float $boost + * @return \Elastica\Query\Wildcard + */ + public function setValue($key, $value, $boost = 1.0) + { + return $this->setParam($key, array('value' => $value, 'boost' => $boost)); + } +} |