summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Suggest
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Suggest
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Suggest')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php97
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php8
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php140
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/Completion.php26
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php164
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php129
6 files changed, 564 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php
new file mode 100644
index 00000000..00f21e44
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php
@@ -0,0 +1,97 @@
+<?php
+namespace Elastica\Suggest;
+
+use Elastica\Param;
+
+/**
+ * Class AbstractSuggestion.
+ */
+abstract class AbstractSuggest extends Param
+{
+ /**
+ * @var string the name of this suggestion
+ */
+ protected $_name;
+
+ /**
+ * @var string the text for this suggestion
+ */
+ protected $_text;
+
+ /**
+ * @param string $name
+ * @param string $field
+ */
+ public function __construct($name, $field)
+ {
+ $this->_name = $name;
+ $this->setField($field);
+ }
+
+ /**
+ * Suggest text must be set either globally or per suggestion.
+ *
+ * @param string $text
+ *
+ * @return $this
+ */
+ public function setText($text)
+ {
+ $this->_text = $text;
+
+ return $this;
+ }
+
+ /**
+ * @param string $field
+ *
+ * @return $this
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * @param int $size
+ *
+ * @return $this
+ */
+ public function setSize($size)
+ {
+ return $this->setParam('size', $size);
+ }
+
+ /**
+ * @param int $size maximum number of suggestions to be retrieved from each shard
+ *
+ * @return $this
+ */
+ public function setShardSize($size)
+ {
+ return $this->setParam('shard_size', $size);
+ }
+
+ /**
+ * Retrieve the name of this suggestion.
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ $array = parent::toArray();
+ if (isset($this->_text)) {
+ $array['text'] = $this->_text;
+ }
+
+ return $array;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php
new file mode 100644
index 00000000..6fba49db
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php
@@ -0,0 +1,8 @@
+<?php
+namespace Elastica\Suggest\CandidateGenerator;
+
+use Elastica\Param;
+
+class AbstractCandidateGenerator extends Param
+{
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php
new file mode 100644
index 00000000..54ac7649
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php
@@ -0,0 +1,140 @@
+<?php
+namespace Elastica\Suggest\CandidateGenerator;
+
+/**
+ * Class DirectGenerator.
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_direct_generators
+ */
+class DirectGenerator extends AbstractCandidateGenerator
+{
+ const SUGGEST_MODE_MISSING = 'missing';
+ const SUGGEST_MODE_POPULAR = 'popular';
+ const SUGGEST_MODE_ALWAYS = 'always';
+
+ /**
+ * @param string $field
+ */
+ public function __construct($field)
+ {
+ $this->setField($field);
+ }
+
+ /**
+ * Set the field name from which to fetch candidate suggestions.
+ *
+ * @param string $field
+ *
+ * @return $this
+ */
+ public function setField($field)
+ {
+ return $this->setParam('field', $field);
+ }
+
+ /**
+ * Set the maximum corrections to be returned per suggest text token.
+ *
+ * @param int $size
+ *
+ * @return $this
+ */
+ public function setSize($size)
+ {
+ return $this->setParam('size', $size);
+ }
+
+ /**
+ * @param string $mode see SUGGEST_MODE_* constants for options
+ *
+ * @return $this
+ */
+ public function setSuggestMode($mode)
+ {
+ return $this->setParam('suggest_mode', $mode);
+ }
+
+ /**
+ * @param int $max can only be a value between 1 and 2. Defaults to 2.
+ *
+ * @return $this
+ */
+ public function setMaxEdits($max)
+ {
+ return $this->setParam('max_edits', $max);
+ }
+
+ /**
+ * @param int $length defaults to 1
+ *
+ * @return $this
+ */
+ public function setPrefixLength($length)
+ {
+ return $this->setParam('prefix_len', $length);
+ }
+
+ /**
+ * @param int $min defaults to 4
+ *
+ * @return $this
+ */
+ public function setMinWordLength($min)
+ {
+ return $this->setParam('min_word_len', $min);
+ }
+
+ /**
+ * @param int $max
+ *
+ * @return $this
+ */
+ public function setMaxInspections($max)
+ {
+ return $this->setParam('max_inspections', $max);
+ }
+
+ /**
+ * @param float $min
+ *
+ * @return $this
+ */
+ public function setMinDocFrequency($min)
+ {
+ return $this->setParam('min_doc_freq', $min);
+ }
+
+ /**
+ * @param float $max
+ *
+ * @return $this
+ */
+ public function setMaxTermFrequency($max)
+ {
+ return $this->setParam('max_term_freq', $max);
+ }
+
+ /**
+ * Set an analyzer to be applied to the original token prior to candidate generation.
+ *
+ * @param string $pre an analyzer
+ *
+ * @return $this
+ */
+ public function setPreFilter($pre)
+ {
+ return $this->setParam('pre_filter', $pre);
+ }
+
+ /**
+ * Set an analyzer to be applied to generated tokens before they are passed to the phrase scorer.
+ *
+ * @param string $post
+ *
+ * @return $this
+ */
+ public function setPostFilter($post)
+ {
+ return $this->setParam('post_filter', $post);
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/Completion.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/Completion.php
new file mode 100644
index 00000000..0f0b3e61
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/Completion.php
@@ -0,0 +1,26 @@
+<?php
+namespace Elastica\Suggest;
+
+/**
+ * Comletion suggester.
+ *
+ * @author Igor Denisenko <im.denisenko@yahoo.com>
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
+ */
+class Completion extends AbstractSuggest
+{
+ /**
+ * Set fuzzy parameter.
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html#fuzzy
+ *
+ * @param array $fuzzy
+ *
+ * @return $this
+ */
+ public function setFuzzy(array $fuzzy)
+ {
+ return $this->setParam('fuzzy', $fuzzy);
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php
new file mode 100644
index 00000000..544f3678
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php
@@ -0,0 +1,164 @@
+<?php
+namespace Elastica\Suggest;
+
+use Elastica\Suggest\CandidateGenerator\AbstractCandidateGenerator;
+
+/**
+ * Class Phrase.
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html
+ */
+class Phrase extends AbstractSuggest
+{
+ /**
+ * @param string $analyzer
+ *
+ * @return $this
+ */
+ public function setAnalyzer($analyzer)
+ {
+ return $this->setParam('analyzer', $analyzer);
+ }
+
+ /**
+ * Set the max size of the n-grams (shingles) in the field.
+ *
+ * @param int $size
+ *
+ * @return $this
+ */
+ public function setGramSize($size)
+ {
+ return $this->setParam('gram_size', $size);
+ }
+
+ /**
+ * Set the likelihood of a term being misspelled even if the term exists in the dictionary.
+ *
+ * @param float $likelihood Defaults to 0.95, meaning 5% of the words are misspelled.
+ *
+ * @return $this
+ */
+ public function setRealWordErrorLikelihood($likelihood)
+ {
+ return $this->setParam('real_word_error_likelihood', $likelihood);
+ }
+
+ /**
+ * Set the factor applied to the input phrases score to be used as a threshold for other suggestion candidates.
+ * Only candidates which score higher than this threshold will be included in the result.
+ *
+ * @param float $confidence Defaults to 1.0.
+ *
+ * @return $this
+ */
+ public function setConfidence($confidence)
+ {
+ return $this->setParam('confidence', $confidence);
+ }
+
+ /**
+ * Set the maximum percentage of the terms considered to be misspellings in order to form a correction.
+ *
+ * @param float $max
+ *
+ * @return $this
+ */
+ public function setMaxErrors($max)
+ {
+ return $this->setParam('max_errors', $max);
+ }
+
+ /**
+ * @param string $separator
+ *
+ * @return $this
+ */
+ public function setSeparator($separator)
+ {
+ return $this->setParam('separator', $separator);
+ }
+
+ /**
+ * Set suggestion highlighting.
+ *
+ * @param string $preTag
+ * @param string $postTag
+ *
+ * @return $this
+ */
+ public function setHighlight($preTag, $postTag)
+ {
+ return $this->setParam('highlight', array(
+ 'pre_tag' => $preTag,
+ 'post_tag' => $postTag,
+ ));
+ }
+
+ /**
+ * @param float $discount
+ *
+ * @return $this
+ */
+ public function setStupidBackoffSmoothing($discount = 0.4)
+ {
+ return $this->setSmoothingModel('stupid_backoff', array(
+ 'discount' => $discount,
+ ));
+ }
+
+ /**
+ * @param float $alpha
+ *
+ * @return $this
+ */
+ public function setLaplaceSmoothing($alpha = 0.5)
+ {
+ return $this->setSmoothingModel('laplace', array(
+ 'alpha' => $alpha,
+ ));
+ }
+
+ /**
+ * @param float $trigramLambda
+ * @param float $bigramLambda
+ * @param float $unigramLambda
+ *
+ * @return $this
+ */
+ public function setLinearInterpolationSmoothing($trigramLambda, $bigramLambda, $unigramLambda)
+ {
+ return $this->setSmoothingModel('linear_interpolation', array(
+ 'trigram_lambda' => $trigramLambda,
+ 'bigram_lambda' => $bigramLambda,
+ 'unigram_lambda' => $unigramLambda,
+ ));
+ }
+
+ /**
+ * @param string $model the name of the smoothing model
+ * @param array $params
+ *
+ * @return $this
+ */
+ public function setSmoothingModel($model, array $params)
+ {
+ return $this->setParam('smoothing', array(
+ $model => $params,
+ ));
+ }
+
+ /**
+ * @param AbstractCandidateGenerator $generator
+ *
+ * @return $this
+ */
+ public function addCandidateGenerator(AbstractCandidateGenerator $generator)
+ {
+ $generator = $generator->toArray();
+ $keys = array_keys($generator);
+ $values = array_values($generator);
+
+ return $this->addParam($keys[0], $values[0]);
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php b/vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php
new file mode 100644
index 00000000..9f082873
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php
@@ -0,0 +1,129 @@
+<?php
+namespace Elastica\Suggest;
+
+/**
+ * Class Term.
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html
+ */
+class Term extends AbstractSuggest
+{
+ const SORT_SCORE = 'score';
+ const SORT_FREQUENCY = 'frequency';
+
+ const SUGGEST_MODE_MISSING = 'missing';
+ const SUGGEST_MODE_POPULAR = 'popular';
+ const SUGGEST_MODE_ALWAYS = 'always';
+
+ /**
+ * @param string $analyzer
+ *
+ * @return $this
+ */
+ public function setAnalyzer($analyzer)
+ {
+ return $this->setParam('analyzer', $analyzer);
+ }
+
+ /**
+ * @param string $sort see SORT_* constants for options
+ *
+ * @return $this
+ */
+ public function setSort($sort)
+ {
+ return $this->setParam('sort', $sort);
+ }
+
+ /**
+ * @param string $mode see SUGGEST_MODE_* constants for options
+ *
+ * @return $this
+ */
+ public function setSuggestMode($mode)
+ {
+ return $this->setParam('suggest_mode', $mode);
+ }
+
+ /**
+ * If true, suggest terms will be lower cased after text analysis.
+ *
+ * @param bool $lowercase
+ *
+ * @return $this
+ */
+ public function setLowercaseTerms($lowercase = true)
+ {
+ return $this->setParam('lowercase_terms', (bool) $lowercase);
+ }
+
+ /**
+ * Set the maximum edit distance candidate suggestions can have in order to be considered as a suggestion.
+ *
+ * @param int $max Either 1 or 2. Any other value will result in an error.
+ *
+ * @return $this
+ */
+ public function setMaxEdits($max)
+ {
+ return $this->setParam('max_edits', (int) $max);
+ }
+
+ /**
+ * The number of minimum prefix characters that must match in order to be a suggestion candidate.
+ *
+ * @param int $length Defaults to 1.
+ *
+ * @return $this
+ */
+ public function setPrefixLength($length)
+ {
+ return $this->setParam('prefix_len', (int) $length);
+ }
+
+ /**
+ * The minimum length a suggest text term must have in order to be included.
+ *
+ * @param int $length Defaults to 4.
+ *
+ * @return $this
+ */
+ public function setMinWordLength($length)
+ {
+ return $this->setParam('min_word_len', (int) $length);
+ }
+
+ /**
+ * @param int $max Defaults to 5.
+ *
+ * @return $this
+ */
+ public function setMaxInspections($max)
+ {
+ return $this->setParam('max_inspections', $max);
+ }
+
+ /**
+ * Set the minimum number of documents in which a suggestion should appear.
+ *
+ * @param int|float $min Defaults to 0. If the value is greater than 1, it must be a whole number.
+ *
+ * @return $this
+ */
+ public function setMinDocFrequency($min)
+ {
+ return $this->setParam('min_doc_freq', $min);
+ }
+
+ /**
+ * Set the maximum number of documents in which a suggest text token can exist in order to be included.
+ *
+ * @param float $max
+ *
+ * @return $this
+ */
+ public function setMaxTermFrequency($max)
+ {
+ return $this->setParam('max_term_freq', $max);
+ }
+}