From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- .../elastica/lib/Elastica/Query/AbstractQuery.php | 13 + vendor/ruflin/elastica/lib/Elastica/Query/Bool.php | 15 + .../elastica/lib/Elastica/Query/BoolQuery.php | 111 +++ .../elastica/lib/Elastica/Query/Boosting.php | 50 ++ .../ruflin/elastica/lib/Elastica/Query/Builder.php | 935 +++++++++++++++++++++ .../ruflin/elastica/lib/Elastica/Query/Common.php | 172 ++++ .../elastica/lib/Elastica/Query/ConstantScore.php | 70 ++ .../ruflin/elastica/lib/Elastica/Query/DisMax.php | 62 ++ .../elastica/lib/Elastica/Query/Filtered.php | 97 +++ .../elastica/lib/Elastica/Query/FunctionScore.php | 260 ++++++ .../ruflin/elastica/lib/Elastica/Query/Fuzzy.php | 87 ++ .../elastica/lib/Elastica/Query/FuzzyLikeThis.php | 217 +++++ .../elastica/lib/Elastica/Query/HasChild.php | 65 ++ .../elastica/lib/Elastica/Query/HasParent.php | 63 ++ vendor/ruflin/elastica/lib/Elastica/Query/Ids.php | 121 +++ .../ruflin/elastica/lib/Elastica/Query/Image.php | 187 +++++ .../ruflin/elastica/lib/Elastica/Query/Match.php | 222 +++++ .../elastica/lib/Elastica/Query/MatchAll.php | 20 + .../elastica/lib/Elastica/Query/MatchPhrase.php | 13 + .../lib/Elastica/Query/MatchPhrasePrefix.php | 13 + .../elastica/lib/Elastica/Query/MoreLikeThis.php | 198 +++++ .../elastica/lib/Elastica/Query/MultiMatch.php | 191 +++++ .../ruflin/elastica/lib/Elastica/Query/Nested.php | 48 ++ .../ruflin/elastica/lib/Elastica/Query/Prefix.php | 47 ++ .../elastica/lib/Elastica/Query/QueryString.php | 282 +++++++ .../ruflin/elastica/lib/Elastica/Query/Range.php | 38 + .../ruflin/elastica/lib/Elastica/Query/Regexp.php | 40 + .../ruflin/elastica/lib/Elastica/Query/Simple.php | 54 ++ .../lib/Elastica/Query/SimpleQueryString.php | 83 ++ vendor/ruflin/elastica/lib/Elastica/Query/Term.php | 49 ++ .../ruflin/elastica/lib/Elastica/Query/Terms.php | 107 +++ .../elastica/lib/Elastica/Query/TopChildren.php | 53 ++ .../elastica/lib/Elastica/Query/Wildcard.php | 40 + 33 files changed, 4023 insertions(+) create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/AbstractQuery.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Bool.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/BoolQuery.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Boosting.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Builder.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Common.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/ConstantScore.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/DisMax.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/FunctionScore.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Fuzzy.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/FuzzyLikeThis.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/HasChild.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/HasParent.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Ids.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Image.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Match.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/MatchAll.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrase.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrasePrefix.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/MoreLikeThis.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/MultiMatch.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Nested.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Prefix.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/QueryString.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Range.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Regexp.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Simple.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Term.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Terms.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/TopChildren.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Query/Wildcard.php (limited to 'vendor/ruflin/elastica/lib/Elastica/Query') 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..fd1c29b0 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/AbstractQuery.php @@ -0,0 +1,13 @@ + + */ +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..c5bccc54 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Bool.php @@ -0,0 +1,15 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html + */ +class Bool extends BoolQuery +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/BoolQuery.php b/vendor/ruflin/elastica/lib/Elastica/Query/BoolQuery.php new file mode 100644 index 00000000..7b8bd4da --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/BoolQuery.php @@ -0,0 +1,111 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html + */ +class BoolQuery extends AbstractQuery +{ + /** + * Add should part to query. + * + * @param \Elastica\Query\AbstractQuery|array $args Should query + * + * @return $this + */ + public function addShould($args) + { + return $this->_addQuery('should', $args); + } + + /** + * Add must part to query. + * + * @param \Elastica\Query\AbstractQuery|array $args Must query + * + * @return $this + */ + 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 $this + */ + 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 + * + * @throws \Elastica\Exception\InvalidException If not valid query + * + * @return $this + */ + 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 $this + */ + public function setBoost($boost) + { + return $this->setParam('boost', $boost); + } + + /** + * Set the minimum number of of should match. + * + * @param int $minimumNumberShouldMatch Should match minimum + * + * @return $this + */ + public function setMinimumNumberShouldMatch($minimumNumberShouldMatch) + { + return $this->setParam('minimum_number_should_match', $minimumNumberShouldMatch); + } + + /** + * Converts array to an object in case no queries are added. + * + * @return array + */ + public function toArray() + { + if (empty($this->_params)) { + $this->_params = new \stdClass(); + } + + return parent::toArray(); + } +} 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..95dcde3d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Boosting.php @@ -0,0 +1,50 @@ + + * + * @link http://www.elastic.co/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 $this + */ + public function setPositiveQuery(AbstractQuery $query) + { + return $this->setParam('positive', $query->toArray()); + } + + /** + * Set the negative query for this Boosting Query. + * + * @param AbstractQuery $query + * + * @return $this + */ + public function setNegativeQuery(AbstractQuery $query) + { + return $this->setParam('negative', $query->toArray()); + } + + /** + * Set the negative_boost parameter for this Boosting Query. + * + * @param Float $negativeBoost + * + * @return $this + */ + 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..55b6b903 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Builder.php @@ -0,0 +1,935 @@ + + * + * @link http://www.elastic.co/ + * @deprecated This builder is deprecated and will be removed. Use new Elastica\QueryBuilder instead. + **/ +class Builder extends AbstractQuery +{ + /** + * Query string. + * + * @var string + */ + private $_string = '{'; + + /** + * Factory method. + * + * @param string $string JSON encoded string to use as query. + * + * @return self + */ + public static function factory($string = null) + { + return new self($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($input = $this->__toString()); + } catch (JSONParseException $e) { + throw new InvalidException(sprintf( + 'The produced query is not a valid json string : "%s"', + $input + )); + } + } + + /** + * Allow wildcards (*, ?) as the first character in a query. + * + * @param bool $bool Defaults to true. + * + * @return $this + */ + public function allowLeadingWildcard($bool = true) + { + return $this->field('allow_leading_wildcard', (bool) $bool); + } + + /** + * Enable best effort analysis of wildcard terms. + * + * @param bool $bool Defaults to true. + * + * @return $this + */ + 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 $this + */ + public function analyzer($analyzer) + { + return $this->field('analyzer', $analyzer); + } + + /** + * Autogenerate phrase queries. + * + * @param bool $bool Defaults to true. + * + * @return $this + */ + 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 $this + */ + public function bool() + { + return $this->fieldOpen('bool'); + } + + /** + * Close a 'bool' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function boolClose() + { + return $this->fieldClose(); + } + + /** + * Sets the boost value of the query. + * + * @param float $boost Defaults to 1.0. + * + * @return $this + */ + public function boost($boost = 1.0) + { + return $this->field('boost', (float) $boost); + } + + /** + * Close a previously opened brace. + * + * @return $this + */ + 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 $this + */ + public function constantScore() + { + return $this->fieldOpen('constant_score'); + } + + /** + * Close a 'constant_score' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function disMax() + { + return $this->fieldOpen('dis_max'); + } + + /** + * Close a 'dis_max' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function disMaxClose() + { + return $this->fieldClose(); + } + + /** + * Enable position increments in result queries. + * + * @param bool $bool Defaults to true. + * + * @return $this + */ + 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 bool $value Turn on / off explain. + * + * @return $this + */ + 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 $this + */ + public function facets() + { + return $this->fieldOpen('facets'); + } + + /** + * Close a facets block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function fieldClose() + { + return $this->close(); + } + + /** + * Open a node for the specified name. + * + * @param string $name Field name. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function filter() + { + return $this->fieldOpen('filter'); + } + + /** + * Close a filter block. + * + * @return $this + */ + public function filterClose() + { + return $this->close(); + } + + /** + * Query. + * + * @return $this + */ + public function filteredQuery() + { + return $this->fieldOpen('filtered'); + } + + /** + * Close a 'filtered_query' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function filteredQueryClose() + { + return $this->fieldClose(); + } + + /** + * Set the from parameter (offset). + * + * @param int $value Result number to start from. + * + * @return $this + */ + 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 $this + */ + public function fuzzyMinSim($value = 0.5) + { + return $this->field('fuzzy_min_sim', (float) $value); + } + + /** + * Set the prefix length for fuzzy queries. + * + * @param int $value Defaults to 0. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function gte($value) + { + return $this->field('gte', $value); + } + + /** + * Automatically lower-case terms of wildcard, prefix, fuzzy, and range queries. + * + * @param bool $bool Defaults to true. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 int $minimum Minimum number that should match. + * + * @return $this + */ + public function minimumNumberShouldMatch($minimum) + { + return $this->field('minimum_number_should_match', (int) $minimum); + } + + /** + * The clause (query) must appear in matching documents. + * + * @return $this + */ + public function must() + { + return $this->fieldOpen('must'); + } + + /** + * Close a 'must' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + 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 $this + */ + public function mustNot() + { + return $this->fieldOpen('must_not'); + } + + /** + * Close a 'must_not' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function mustNotClose() + { + return $this->fieldClose(); + } + + /** + * Add an opening brace. + * + * @return $this + */ + public function open() + { + $this->_string .= '{'; + + return $this; + } + + /** + * Sets the default slop for phrases. + * + * If zero, then exact phrase matches are required. + * + * @param int $value Defaults to 0. + * + * @return $this + */ + public function phraseSlop($value = 0) + { + return $this->field('phrase_slop', (int) $value); + } + + /** + * Query. + * + * @return $this + */ + public function prefix() + { + return $this->fieldOpen('prefix'); + } + + /** + * Close a 'prefix' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function prefixClose() + { + return $this->fieldClose(); + } + + /** + * Queries to run within a dis_max query. + * + * @param array $queries Array of queries. + * + * @return $this + */ + 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 $this + */ + public function query() + { + return $this->fieldOpen('query'); + } + + /** + * Close a query block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function queryClose() + { + return $this->close(); + } + + /** + * Query String Query. + * + * A query that uses a query parser in order to parse its content + * + * @return $this + */ + public function queryString() + { + return $this->fieldOpen('query_string'); + } + + /** + * Close a 'query_string' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function queryStringClose() + { + return $this->fieldClose(); + } + + /** + * Open a range block. + * + * @return $this + */ + public function range() + { + return $this->fieldOpen('range'); + } + + /** + * Close a range block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + 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 $this + */ + public function should() + { + return $this->fieldOpen('should'); + } + + /** + * Close a 'should' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function shouldClose() + { + return $this->fieldClose(); + } + + /** + * Set the size parameter (number of records to return). + * + * @param int $value Number of records to return. + * + * @return $this + */ + public function size($value = 10) + { + return $this->field('size', $value); + } + + /** + * Allows to add one or more sort on specific fields. + * + * @return $this + */ + public function sort() + { + return $this->fieldOpen('sort'); + } + + /** + * Close a sort block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function sortClose() + { + return $this->close(); + } + + /** + * Add a field to sort on. + * + * @param string $name Field to sort. + * @param bool $reverse Reverse direction. + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function term() + { + return $this->fieldOpen('term'); + } + + /** + * Close a 'term' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + public function termClose() + { + return $this->fieldClose(); + } + + /** + * Open a 'text_phrase' block. + * + * @return $this + */ + public function textPhrase() + { + return $this->fieldOpen('text_phrase'); + } + + /** + * Close a 'text_phrase' block. + * + * @return $this + */ + public function textPhraseClose() + { + return $this->close(); + } + + /** + * When using dis_max, the disjunction max tie breaker. + * + * @param float $multiplier Multiplier to use. + * + * @return $this + */ + public function tieBreakerMultiplier($multiplier) + { + return $this->field('tie_breaker_multiplier', (float) $multiplier); + } + + /** + * Query. + * + * @return $this + */ + public function wildcard() + { + return $this->fieldOpen('wildcard'); + } + + /** + * Close a 'wildcard' block. + * + * Alias of close() for ease of reading in source. + * + * @return $this + */ + 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..9ca58d2e --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Common.php @@ -0,0 +1,172 @@ +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 $this + */ + public function setField($field) + { + $this->_field = $field; + + return $this; + } + + /** + * Set the query string for this query. + * + * @param string $query + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + * + * @link Possible values for minimum_should_match http://www.elastic.co/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 $this + */ + public function setBoost($boost) + { + return $this->setQueryParam('boost', (float) $boost); + } + + /** + * Set the analyzer for this query. + * + * @param string $analyzer + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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(); + } +} 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..3578606d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/ConstantScore.php @@ -0,0 +1,70 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + public function setQuery($query) + { + if ($query instanceof AbstractQuery) { + $query = $query->toArray(); + } + + return $this->setParam('query', $query); + } + + /** + * Set boost. + * + * @param float $boost + * + * @return $this + */ + 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..b3c5f252 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/DisMax.php @@ -0,0 +1,62 @@ + + * + * @link http://www.elastic.co/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 + * + * @throws \Elastica\Exception\InvalidException If not valid query + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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..ac085037 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Filtered.php @@ -0,0 +1,97 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + public function setQuery(AbstractQuery $query = null) + { + return $this->setParam('query', $query); + } + + /** + * Sets the filter. + * + * @param \Elastica\Filter\AbstractFilter $filter Filter object + * + * @return $this + */ + 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..b11454fb --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/FunctionScore.php @@ -0,0 +1,260 @@ +setParam('query', $query->toArray()); + } + + /** + * @param AbstractFilter $filter + * + * @return $this + */ + 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 + * @param float $weight function weight + * + * @return $this + */ + public function addFunction($functionType, $functionParams, AbstractFilter $filter = null, $weight = null) + { + $function = array( + $functionType => $functionParams, + ); + if (!is_null($filter)) { + $function['filter'] = $filter->toArray(); + } + if ($weight !== null) { + $function['weight'] = $weight; + } + + $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 + * @param float $weight the weight of the function + * + * @return $this + */ + public function addScriptScoreFunction(Script $script, AbstractFilter $filter = null, $weight = null) + { + return $this->addFunction('script_score', $script->toArray(), $filter, $weight); + } + + /** + * 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 float $weight 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 $this + */ + public function addDecayFunction( + $function, + $field, + $origin, + $scale, + $offset = null, + $decay = null, + $weight = 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; + } + + return $this->addFunction($function, $functionParams, $filter, $weight); + } + + /** + * Add a boost_factor function to the query. + * + * @param float $boostFactor the boost factor value + * @param AbstractFilter $filter a filter associated with this function + * + * @deprecated + */ + public function addBoostFactorFunction($boostFactor, AbstractFilter $filter = null) + { + $this->addWeightFunction($boostFactor, $filter); + } + + /** + * @param float $weight the weight of the function + * @param AbstractFilter $filter a filter associated with this function + */ + public function addWeightFunction($weight, AbstractFilter $filter = null) + { + $this->addFunction('weight', $weight, $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 $weight an optional boost value associated with this function + */ + public function addRandomScoreFunction($seed, AbstractFilter $filter = null, $weight = null) + { + $this->addFunction('random_score', array('seed' => $seed), $filter, $weight); + } + + /** + * Set an overall boost value for this query. + * + * @param float $boost + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function setScoreMode($mode) + { + return $this->setParam('score_mode', $mode); + } + + /** + * Set min_score option. + * + * @param float $minScore + * + * @return $this + */ + public function setMinScore($minScore) + { + return $this->setParam('min_score', (float) $minScore); + } + + /** + * @return array + */ + public function toArray() + { + if (sizeof($this->_functions)) { + $this->setParam('functions', $this->_functions); + } + + return parent::toArray(); + } +} 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..a3a46693 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Fuzzy.php @@ -0,0 +1,87 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 + */ + 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 $this + */ + 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 $this + */ + 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..2de480a8 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/FuzzyLikeThis.php @@ -0,0 +1,217 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 bool 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 $this + */ + public function addFields(array $fields) + { + $this->_fields = $fields; + + return $this; + } + + /** + * Set the "like_text" value. + * + * @param string $text + * + * @return $this + */ + public function setLikeText($text) + { + $text = trim($text); + $this->_likeText = $text; + + return $this; + } + + /** + * Set the "ignore_tf" value (ignore term frequency). + * + * @param bool $ignoreTF + * + * @return $this + */ + public function setIgnoreTF($ignoreTF) + { + $this->_ignoreTF = (bool) $ignoreTF; + + return $this; + } + + /** + * Set the minimum similarity. + * + * @param int $value + * + * @return $this + */ + public function setMinSimilarity($value) + { + $value = (float) $value; + $this->_minSimilarity = $value; + + return $this; + } + + /** + * Set boost. + * + * @param float $value Boost value + * + * @return $this + */ + public function setBoost($value) + { + $this->_boost = (float) $value; + + return $this; + } + + /** + * Set Prefix Length. + * + * @param int $value Prefix length + * + * @return $this + */ + public function setPrefixLength($value) + { + $this->_prefixLength = (int) $value; + + return $this; + } + + /** + * Set max_query_terms. + * + * @param int $value Max query terms value + * + * @return $this + */ + public function setMaxQueryTerms($value) + { + $this->_maxQueryTerms = (int) $value; + + return $this; + } + + /** + * Set analyzer. + * + * @param string $text Analyzer text + * + * @return $this + */ + 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->_analyzer)) { + $args['analyzer'] = $this->_analyzer; + } + + $args['min_similarity'] = ($this->_minSimilarity > 0) ? $this->_minSimilarity : 0; + + $args['like_text'] = $this->_likeText; + $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..190fa592 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/HasChild.php @@ -0,0 +1,65 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Sets the scope. + * + * @param string $scope Scope + * + * @return $this + */ + 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..03aae13b --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/HasParent.php @@ -0,0 +1,63 @@ +setQuery($query); + $this->setType($type); + } + + /** + * Sets query object. + * + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query + * + * @return $this + */ + 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 $this + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Sets the scope. + * + * @param string $scope Scope + * + * @return $this + */ + 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..5d76efcf --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Ids.php @@ -0,0 +1,121 @@ + + * @author Tim Rupp + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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/Image.php b/vendor/ruflin/elastica/lib/Elastica/Query/Image.php new file mode 100644 index 00000000..bf7d028b --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Image.php @@ -0,0 +1,187 @@ + + * + * @link https://github.com/kzwang/elasticsearch-image + * + * To use this feature you have to call the following command in the + * elasticsearch directory: + * + * ./bin/plugin --url https://github.com/SibaTokyo/elasticsearch-image/releases/download/1.4.0/elasticsearch-image-1.4.0.zip --install image + * + * This installs the image plugin. More infos + * can be found here: {@link https://github.com/SibaTokyo/elasticsearch-image} + */ +class Image extends AbstractQuery +{ + public function __construct(array $image = array()) + { + $this->setParams($image); + } + + /** + * Sets a param for the given field. + * + * @param string $field + * @param string $key + * @param string $value + * + * @return $this + */ + public function setFieldParam($field, $key, $value) + { + if (!isset($this->_params[$field])) { + $this->_params[$field] = array(); + } + + $this->_params[$field][$key] = $value; + + return $this; + } + + /** + * Set field boost value. + * + * If not set, defaults to 1.0. + * + * @param string $field + * @param float $boost + * + * @return $this + */ + public function setFieldBoost($field, $boost = 1.0) + { + return $this->setFieldParam($field, 'boost', (float) $boost); + } + + /** + * Set field feature value. + * + * If not set, defaults CEDD. + * + * @param string $field + * @param string $feature + * + * @return $this + */ + public function setFieldFeature($field, $feature = 'CEDD') + { + return $this->setFieldParam($field, 'feature', $feature); + } + + /** + * Set field hash value. + * + * If not set, defaults BIT_SAMPLING. + * + * @param string $field + * @param string $hash + * + * @return $this + */ + public function setFieldHash($field, $hash = 'BIT_SAMPLING') + { + return $this->setFieldParam($field, 'hash', $hash); + } + + /** + * Set field image value. + * + * @param string $field + * @param string $path File will be base64_encode + * + * @throws \Exception + * + * @return $this + */ + public function setFieldImage($field, $path) + { + if (!file_exists($path) || !is_readable($path)) { + throw new \Exception(sprintf("File %s can't be open", $path)); + } + + return $this->setFieldParam($field, 'image', base64_encode(file_get_contents($path))); + } + + /** + * Set field index value. + * + * @param string $field + * @param string $index + * + * @return $this + */ + public function setFieldIndex($field, $index) + { + return $this->setFieldParam($field, 'index', $index); + } + + /** + * Set field type value. + * + * @param string $field + * @param string $type + * + * @return $this + */ + public function setFieldType($field, $type) + { + return $this->setFieldParam($field, 'type', $type); + } + + /** + * Set field id value. + * + * @param string $field + * @param string $id + * + * @return $this + */ + public function setFieldId($field, $id) + { + return $this->setFieldParam($field, 'id', $id); + } + + /** + * Set field path value. + * + * @param string $field + * @param string $path + * + * @return $this + */ + public function setFieldPath($field, $path) + { + return $this->setFieldParam($field, 'path', $path); + } + + /** + * Define quickly a reference image already in your elasticsearch database. + * + * If not set, path will be the same as $field. + * + * @param string $field + * @param string $index + * @param string $type + * @param string $id + * @param string $path + * + * @return $this + */ + public function setImageByReference($field, $index, $type, $id, $path = null) + { + if (null === $path) { + $path = $field; + } + + $this->setFieldIndex($field, $index); + $this->setFieldType($field, $type); + $this->setFieldId($field, $id); + + return $this->setFieldPath($field, $path); + } +} 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..abb40970 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Match.php @@ -0,0 +1,222 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html + */ +class Match extends AbstractQuery +{ + const ZERO_TERM_NONE = 'none'; + const ZERO_TERM_ALL = 'all'; + + /** + * @param string $field + * @param mixed $values + */ + public function __construct($field = null, $values = null) + { + if ($field !== null && $values !== null) { + $this->setParam($field, $values); + } + } + + /** + * Sets a param for the message array. + * + * @param string $field + * @param mixed $values + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function setFieldQuery($field, $query) + { + return $this->setFieldParam($field, 'query', $query); + } + + /** + * Set field type. + * + * @param string $field + * @param string $type + * + * @return $this + */ + public function setFieldType($field, $type) + { + return $this->setFieldParam($field, 'type', $type); + } + + /** + * Set field operator. + * + * @param string $field + * @param string $operator + * + * @return $this + */ + public function setFieldOperator($field, $operator) + { + return $this->setFieldParam($field, 'operator', $operator); + } + + /** + * Set field analyzer. + * + * @param string $field + * @param string $analyzer + * + * @return $this + */ + 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 $this + */ + 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 $this + * + * @link Possible values for minimum_should_match http://www.elastic.co/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 $this + */ + public function setFieldFuzziness($field, $fuzziness) + { + return $this->setFieldParam($field, 'fuzziness', $fuzziness); + } + + /** + * Set field fuzzy rewrite. + * + * @param string $field + * @param string $fuzzyRewrite + * + * @return $this + */ + public function setFieldFuzzyRewrite($field, $fuzzyRewrite) + { + return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite); + } + + /** + * Set field prefix length. + * + * @param string $field + * @param int $prefixLength + * + * @return $this + */ + public function setFieldPrefixLength($field, $prefixLength) + { + return $this->setFieldParam($field, 'prefix_length', (int) $prefixLength); + } + + /** + * Set field max expansions. + * + * @param string $field + * @param int $maxExpansions + * + * @return $this + */ + 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 $this + */ + public function setFieldZeroTermsQuery($field, $zeroTermQuery = 'none') + { + return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery); + } + + /** + * Set cutoff frequency. + * + * @param string $field + * @param float $cutoffFrequency + * + * @return $this + */ + 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..d01aaee8 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MatchAll.php @@ -0,0 +1,20 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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/MatchPhrase.php b/vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrase.php new file mode 100644 index 00000000..54302f90 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrase.php @@ -0,0 +1,13 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_phrase + */ +class MatchPhrase extends Match +{ +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrasePrefix.php b/vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrasePrefix.php new file mode 100644 index 00000000..61764bda --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MatchPhrasePrefix.php @@ -0,0 +1,13 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_match_phrase_prefix + */ +class MatchPhrasePrefix extends Match +{ +} 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..cd375db5 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MoreLikeThis.php @@ -0,0 +1,198 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html + */ +class MoreLikeThis extends AbstractQuery +{ + /** + * Set fields to which to restrict the mlt query. + * + * @param array $fields Field names + * + * @return \Elastica\Query\MoreLikeThis Current object + */ + public function setFields(array $fields) + { + return $this->setParam('fields', $fields); + } + + /** + * Set document ids for the mlt query. + * + * @param array $ids Document ids + * + * @return \Elastica\Query\MoreLikeThis Current object + */ + public function setIds(array $ids) + { + return $this->setParam('ids', $ids); + } + + /** + * Set the "like_text" value. + * + * @param string $likeText + * + * @return $this + */ + public function setLikeText($likeText) + { + $likeText = trim($likeText); + + return $this->setParam('like_text', $likeText); + } + + /** + * Set boost. + * + * @param float $boost Boost value + * + * @return $this + */ + public function setBoost($boost) + { + return $this->setParam('boost', (float) $boost); + } + + /** + * Set max_query_terms. + * + * @param int $maxQueryTerms Max query terms value + * + * @return $this + */ + public function setMaxQueryTerms($maxQueryTerms) + { + return $this->setParam('max_query_terms', (int) $maxQueryTerms); + } + + /** + * Set percent terms to match. + * + * @param float $percentTermsToMatch Percentage + * + * @return $this + * + * @deprecated Option "percent_terms_to_match" deprecated as of ES 1.5. Use "minimum_should_match" instead. + */ + public function setPercentTermsToMatch($percentTermsToMatch) + { + return $this->setParam('percent_terms_to_match', (float) $percentTermsToMatch); + } + + /** + * Set min term frequency. + * + * @param int $minTermFreq + * + * @return $this + */ + public function setMinTermFrequency($minTermFreq) + { + return $this->setParam('min_term_freq', (int) $minTermFreq); + } + + /** + * set min document frequency. + * + * @param int $minDocFreq + * + * @return $this + */ + public function setMinDocFrequency($minDocFreq) + { + return $this->setParam('min_doc_freq', (int) $minDocFreq); + } + + /** + * set max document frequency. + * + * @param int $maxDocFreq + * + * @return $this + */ + public function setMaxDocFrequency($maxDocFreq) + { + return $this->setParam('max_doc_freq', (int) $maxDocFreq); + } + + /** + * Set min word length. + * + * @param int $minWordLength + * + * @return $this + */ + public function setMinWordLength($minWordLength) + { + return $this->setParam('min_word_length', (int) $minWordLength); + } + + /** + * Set max word length. + * + * @param int $maxWordLength + * + * @return $this + */ + public function setMaxWordLength($maxWordLength) + { + return $this->setParam('max_word_length', (int) $maxWordLength); + } + + /** + * Set boost terms. + * + * @param bool $boostTerms + * + * @return $this + */ + public function setBoostTerms($boostTerms) + { + return $this->setParam('boost_terms', (bool) $boostTerms); + } + + /** + * Set analyzer. + * + * @param string $analyzer + * + * @return $this + */ + public function setAnalyzer($analyzer) + { + $analyzer = trim($analyzer); + + return $this->setParam('analyzer', $analyzer); + } + + /** + * Set stop words. + * + * @param array $stopWords + * + * @return $this + */ + public function setStopWords(array $stopWords) + { + return $this->setParam('stop_words', $stopWords); + } + + /** + * Set minimum_should_match option. + * + * @param int|string $minimumShouldMatch + * + * @return $this + */ + public function setMinimumShouldMatch($minimumShouldMatch) + { + return $this->setParam('minimum_should_match', $minimumShouldMatch); + } +} 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..0771f370 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/MultiMatch.php @@ -0,0 +1,191 @@ + + * @author Wong Wing Lun + * @author Tristan Maindron + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + public function setQuery($query = '') + { + return $this->setParam('query', $query); + } + + /** + * Sets Fields to be used in the query. + * + * @param array $fields Fields + * + * @return $this + */ + 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 bool $useDisMax + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + public function setOperator($operator = 'or') + { + return $this->setParam('operator', $operator); + } + + /** + * Set field minimum should match for Match Query. + * + * @param mixed $minimumShouldMatch + * + * @return $this + */ + public function setMinimumShouldMatch($minimumShouldMatch) + { + return $this->setParam('minimum_should_match', $minimumShouldMatch); + } + + /** + * Set zero terms query for Match Query. + * + * If not set, default to 'none' + * + * @param string $zeroTermQuery + * + * @return $this + */ + public function setZeroTermsQuery($zeroTermQuery = 'none') + { + return $this->setParam('zero_terms_query', $zeroTermQuery); + } + + /** + * Set cutoff frequency for Match Query. + * + * @param float $cutoffFrequency + * + * @return $this + */ + public function setCutoffFrequency($cutoffFrequency) + { + return $this->setParam('cutoff_frequency', $cutoffFrequency); + } + + /** + * Set type. + * + * @param string $field + * @param string $type + * + * @return $this + */ + public function setType($type) + { + return $this->setParam('type', $type); + } + + /** + * Set fuzziness. + * + * @param float $fuzziness + * + * @return $this + */ + public function setFuzziness($fuzziness) + { + return $this->setParam('fuzziness', (float) $fuzziness); + } + + /** + * Set prefix length. + * + * @param int $prefixLength + * + * @return $this + */ + public function setPrefixLength($prefixLength) + { + return $this->setParam('prefix_length', (int) $prefixLength); + } + + /** + * Set max expansions. + * + * @param int $maxExpansions + * + * @return $this + */ + public function setMaxExpansions($maxExpansions) + { + return $this->setParam('max_expansions', (int) $maxExpansions); + } + + /** + * Set analyzer. + * + * @param string $analyzer + * + * @return $this + */ + 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..b072cfc8 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Nested.php @@ -0,0 +1,48 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html + */ +class Nested extends AbstractQuery +{ + /** + * Adds field to mlt query. + * + * @param string $path Nested object path + * + * @return $this + */ + public function setPath($path) + { + return $this->setParam('path', $path); + } + + /** + * Sets nested query. + * + * @param \Elastica\Query\AbstractQuery $query + * + * @return $this + */ + public function setQuery(AbstractQuery $query) + { + return $this->setParam('query', $query->toArray()); + } + + /** + * Set score method. + * + * @param string $scoreMode Options: avg, total, max and none. + * + * @return $this + */ + 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..c2b903ea --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Prefix.php @@ -0,0 +1,47 @@ +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 $this + */ + 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 $this + */ + 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..89ea77cd --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/QueryString.php @@ -0,0 +1,282 @@ +, Jasper van Wanrooy + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 If given parameter is not a string + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function setAllowLeadingWildcard($allow = true) + { + return $this->setParam('allow_leading_wildcard', (bool) $allow); + } + + /** + * Sets the parameter to enable the position increments in result queries. + * + * If not set, defaults to true. + * + * @param bool $enabled + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + 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 If given parameter is not an array + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function setRewrite($rewrite = '') + { + return $this->setParam('rewrite', $rewrite); + } + + /** + * Set timezone option. + * + * @param string $timezone + * + * @return $this + */ + public function setTimezone($timezone) + { + return $this->setParam('time_zone', $timezone); + } + + /** + * 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..b2f9175a --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Range.php @@ -0,0 +1,38 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + public function addField($fieldName, array $args) + { + return $this->setParam($fieldName, $args); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Query/Regexp.php b/vendor/ruflin/elastica/lib/Elastica/Query/Regexp.php new file mode 100644 index 00000000..22a48560 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Regexp.php @@ -0,0 +1,40 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html + */ +class Regexp extends AbstractQuery +{ + /** + * Construct regexp query. + * + * @param string $key OPTIONAL Regexp key + * @param string $value OPTIONAL Regexp 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 $this + */ + public function setValue($key, $value, $boost = 1.0) + { + return $this->setParam($key, array('value' => $value, 'boost' => $boost)); + } +} 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..6ba9310d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Simple.php @@ -0,0 +1,54 @@ + + */ +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 $this + */ + 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..c2302d44 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php @@ -0,0 +1,83 @@ +setQuery($query); + if (sizeof($fields)) { + $this->setFields($fields); + } + } + + /** + * Set the querystring for this query. + * + * @param string $query see ES documentation for querystring syntax + * + * @return $this + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function setAnalyzer($analyzer) + { + return $this->setParam('analyzer', $analyzer); + } + + /** + * Set minimum_should_match option. + * + * @param int|string $minimumShouldMatch + * + * @return $this + */ + public function setMinimumShouldMatch($minimumShouldMatch) + { + return $this->setParam('minimum_should_match', $minimumShouldMatch); + } +} 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..8cfe0a88 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Term.php @@ -0,0 +1,49 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + 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..54f26461 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Terms.php @@ -0,0 +1,107 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + public function addTerm($term) + { + $this->_terms[] = $term; + + return $this; + } + + /** + * Sets the minimum matching values. + * + * @param int $minimum Minimum value + * + * @return $this + */ + 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 If term key is empty + * + * @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..6f15c79d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/TopChildren.php @@ -0,0 +1,53 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + 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 $this + */ + 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..bfa5e751 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Query/Wildcard.php @@ -0,0 +1,40 @@ + + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/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 $this + */ + public function setValue($key, $value, $boost = 1.0) + { + return $this->setParam($key, array('value' => $value, 'boost' => $boost)); + } +} -- cgit v1.2.3-54-g00ecf