forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor suggest implementation to more closely resemble query implem…
…entation
- Loading branch information
Showing
13 changed files
with
674 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_Store | ||
.idea | ||
*.iml | ||
.vagrant | ||
.* | ||
cache.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Elastica; | ||
|
||
|
||
use Elastica\Param; | ||
use Elastica\Suggest\AbstractSuggest; | ||
|
||
/** | ||
* Class Suggest | ||
* @package Elastica\Suggest | ||
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html | ||
*/ | ||
class Suggest extends Param | ||
{ | ||
/** | ||
* Set the global text for this suggester | ||
* @param string $text | ||
* @return \Elastica\Suggest | ||
*/ | ||
public function setGlobalText($text) | ||
{ | ||
return $this->setParam("text", $text); | ||
} | ||
|
||
public function addSuggestion(AbstractSuggest $suggestion) | ||
{ | ||
return $this->setParam($suggestion->getName(), $suggestion->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,88 @@ | ||
<?php | ||
|
||
namespace Elastica\Suggest; | ||
|
||
|
||
use Elastica\Param; | ||
|
||
/** | ||
* Abstract suggest object. Should be extended by all suggest types. | ||
* | ||
* @category Xodoa | ||
* @package Elastica | ||
* @author Imanol Cea <[email protected]> | ||
* 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; | ||
|
||
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; | ||
} | ||
} |
Oops, something went wrong.