summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Suggest
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-08-16 08:22:05 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-08-16 08:22:05 +0200
commit1a365e77dfb8825136626202b1df462731b42060 (patch)
tree1dc4468eaabf070e051e790a9e67a9a9a2c63d99 /vendor/ruflin/elastica/lib/Elastica/Suggest
parenta72fd280f7acb4d2a1ba579a0f1b2b2ae8958530 (diff)
Update to MediaWiki 1.25.2
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Suggest')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php92
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php11
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php127
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php148
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php115
5 files changed, 493 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..e5f5e01c
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/AbstractSuggest.php
@@ -0,0 +1,92 @@
+<?php
+
+namespace Elastica\Suggest;
+
+
+use Elastica\Param;
+
+/**
+ * Class AbstractSuggestion
+ * @package Elastica\Suggest
+ */
+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 \Elastica\Suggest\AbstractSuggest
+ */
+ public function setText($text)
+ {
+ $this->_text = $text;
+ return $this;
+ }
+
+ /**
+ * @param string $field
+ * @return \Elastica\Suggest\AbstractSuggest
+ */
+ public function setField($field)
+ {
+ return $this->setParam("field", $field);
+ }
+
+ /**
+ * @param int $size
+ * @return \Elastica\Suggest\AbstractSuggest
+ */
+ public function setSize($size)
+ {
+ return $this->setParam("size", $size);
+ }
+
+ /**
+ * @param int $size maximum number of suggestions to be retrieved from each shard
+ * @return \Elastica\Suggest\AbstractSuggest
+ */
+ 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;
+ }
+} \ No newline at end of file
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..d9e6ac7c
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Elastica\Suggest\CandidateGenerator;
+
+
+use Elastica\Param;
+
+class AbstractCandidateGenerator extends Param
+{
+
+} \ No newline at end of file
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..0277a5ac
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php
@@ -0,0 +1,127 @@
+<?php
+
+namespace Elastica\Suggest\CandidateGenerator;
+
+
+/**
+ * Class DirectGenerator
+ * @package Elastica\Suggest\Phrase
+ * @link http://www.elasticsearch.org/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 DirectGenerator
+ */
+ public function setField($field)
+ {
+ return $this->setParam("field", $field);
+ }
+
+ /**
+ * Set the maximum corrections to be returned per suggest text token
+ * @param int $size
+ * @return DirectGenerator
+ */
+ public function setSize($size)
+ {
+ return $this->setParam("size", $size);
+ }
+
+ /**
+ * @param string $mode see SUGGEST_MODE_* constants for options
+ * @return DirectGenerator
+ */
+ 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 DirectGenerator
+ */
+ public function setMaxEdits($max)
+ {
+ return $this->setParam("max_edits", $max);
+ }
+
+ /**
+ * @param int $length defaults to 1
+ * @return DirectGenerator
+ */
+ public function setPrefixLength($length)
+ {
+ return $this->setParam("prefix_len", $length);
+ }
+
+ /**
+ * @param int $min defaults to 4
+ * @return DirectGenerator
+ */
+ public function setMinWordLength($min)
+ {
+ return $this->setParam("min_word_len", $min);
+ }
+
+ /**
+ * @param int $max
+ * @return DirectGenerator
+ */
+ public function setMaxInspections($max)
+ {
+ return $this->setParam("max_inspections", $max);
+ }
+
+ /**
+ * @param float $min
+ * @return DirectGenerator
+ */
+ public function setMinDocFrequency($min)
+ {
+ return $this->setParam("min_doc_freq", $min);
+ }
+
+ /**
+ * @param float $max
+ * @return DirectGenerator
+ */
+ 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 DirectGenerator
+ */
+ 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 DirectGenerator
+ */
+ public function setPostFilter($post)
+ {
+ return $this->setParam("post_filter", $post);
+ }
+} \ No newline at end of file
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..14630dc1
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/Phrase.php
@@ -0,0 +1,148 @@
+<?php
+
+namespace Elastica\Suggest;
+
+use Elastica\Suggest\CandidateGenerator\AbstractCandidateGenerator;
+
+
+/**
+ * Class Phrase
+ * @package Elastica\Suggest
+ * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html
+ */
+class Phrase extends AbstractSuggest
+{
+ /**
+ * @param string $analyzer
+ * @return \Elastica\Suggest\Phrase
+ */
+ 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 \Elastica\Suggest\Phrase
+ */
+ 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 \Elastica\Suggest\Phrase
+ */
+ public function setRealWorldErrorLikelihood($likelihood)
+ {
+ return $this->setParam("real_world_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 \Elastica\Suggest\Phrase
+ */
+ 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 \Elastica\Suggest\Phrase
+ */
+ public function setMaxErrors($max)
+ {
+ return $this->setParam("max_errors", $max);
+ }
+
+ /**
+ * @param string $separator
+ * @return \Elastica\Param
+ */
+ public function setSeparator($separator)
+ {
+ return $this->setParam("separator", $separator);
+ }
+
+ /**
+ * Set suggestion highlighting
+ * @param string $preTag
+ * @param string $postTag
+ * @return \Elastica\Suggest\Phrase
+ */
+ public function setHighlight($preTag, $postTag)
+ {
+ return $this->setParam("highlight", array(
+ 'pre_tag' => $preTag,
+ 'post_tag' => $postTag
+ ));
+ }
+
+ /**
+ * @param float $discount
+ * @return \Elastica\Suggest\Phrase
+ */
+ public function setStupidBackoffSmoothing($discount = 0.4)
+ {
+ return $this->setSmoothingModel("stupid_backoff", array(
+ "discount" => $discount
+ ));
+ }
+
+ /**
+ * @param float $alpha
+ * @return \Elastica\Suggest\Phrase
+ */
+ public function setLaplaceSmoothing($alpha = 0.5)
+ {
+ return $this->setSmoothingModel("laplace", array(
+ "alpha" => $alpha
+ ));
+ }
+
+ /**
+ * @param float $trigramLambda
+ * @param float $bigramLambda
+ * @param float $unigramLambda
+ * @return \Elastica\Suggest\Phrase
+ */
+ 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 \Elastica\Suggest\Phrase
+ */
+ public function setSmoothingModel($model, array $params)
+ {
+ return $this->setParam("smoothing", array(
+ $model => $params
+ ));
+ }
+
+ /**
+ * @param AbstractCandidateGenerator $generator
+ * @return \Elastica\Suggest\Phrase
+ */
+ public function addCandidateGenerator(AbstractCandidateGenerator $generator)
+ {
+ $generator = $generator->toArray();
+ $keys = array_keys($generator);
+ $values = array_values($generator);
+ return $this->addParam($keys[0], $values[0]);
+ }
+} \ No newline at end of file
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..3fca1731
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Suggest/Term.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Elastica\Suggest;
+
+
+/**
+ * Class Term
+ * @package Elastica\Suggest
+ * @link http://www.elasticsearch.org/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 \Elastica\Suggest\Term
+ */
+ public function setAnalyzer($analyzer)
+ {
+ return $this->setParam("analyzer", $analyzer);
+ }
+
+ /**
+ * @param string $sort see SORT_* constants for options
+ * @return \Elastica\Suggest\Term
+ */
+ public function setSort($sort)
+ {
+ return $this->setParam("sort", $sort);
+ }
+
+ /**
+ * @param string $mode see SUGGEST_MODE_* constants for options
+ * @return \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ public function setMinWordLength($length)
+ {
+ return $this->setParam("min_word_len", (int)$length);
+ }
+
+ /**
+ * @param int $max Defaults to 5.
+ * @return \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ 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 \Elastica\Suggest\Term
+ */
+ public function setMaxTermFrequency($max)
+ {
+ return $this->setParam("max_term_freq", $max);
+ }
+} \ No newline at end of file