/** * @return \Elastica\ResultSet */ public function getSuggestions() { $suggestPhrase = new Suggest\Phrase('content-suggester', 'content'); $suggestPhrase->setText($this->data); $suggestPhrase->setHighlight("<strong>", "</strong>"); $suggestPhrase->setAnalyzer('suggestion_analyzer'); $suggestPhrase->setConfidence(2); $suggestPhrase->setSize(1); $suggest = new Suggest($suggestPhrase); $this->query->setSuggest($suggest); return $this->getSearchResult(); }
public function testPhraseSuggest() { $suggest = new Suggest(); $phraseSuggest = new Phrase('suggest1', 'text'); $phraseSuggest->setText("elasticsearch is bansai coor"); $phraseSuggest->setAnalyzer("simple")->setHighlight("<suggest>", "</suggest>")->setStupidBackoffSmoothing(0.4); $phraseSuggest->addCandidateGenerator(new DirectGenerator("text")); $suggest->addSuggestion($phraseSuggest); $result = $this->_index->search($suggest); $suggests = $result->getSuggests(); // 3 suggestions should be returned: One in which both misspellings are corrected, and two in which only one misspelling is corrected. $this->assertEquals(3, sizeof($suggests['suggest1'][0]['options'])); $this->assertEquals("elasticsearch is <suggest>bonsai cool</suggest>", $suggests['suggest1'][0]['options'][0]['highlighted']); $this->assertEquals("elasticsearch is bonsai cool", $suggests['suggest1'][0]['options'][0]['text']); }