/** * {@inheritdoc} */ public function findUser($token) { $query = new \Elastica\Query\Fuzzy(); $query->setField('username', $token); $finalQuery = new \Elastica\Query($query); $finalQuery->setFields(['username', 'profilePicture']); $finalQuery->setHighlight(['pre_tags' => ['<em style="color: #FF66FF;">'], 'post_tags' => ['</em>'], 'fields' => ['username' => ['fragment_size' => 200, 'number_of_fragments' => 1]]]); $users = $this->finder->search($finalQuery); $results = []; foreach ($users as $user) { $results[] = ['username' => $user->getData()['username'][0], 'profilePicture' => $user->getData()['profilePicture'][0], 'highlights' => $user->getHighlights()['username'][0]]; } return $results; }
/** * @param $keyword * @return \Elastica\ResultSet */ public function search($keyword) { $query = new Query(); $query->setSize(1000); $fuzzyQuery = new Query\FuzzyLikeThis(); $fuzzyQuery->setLikeText($keyword); $fuzzyQuery->setMinSimilarity(0.7); $query->setQuery($fuzzyQuery); $results = $this->search->search($query); return $results; }
/** * Creates new search object * * @param \Elastica\SearchableInterface $searchObject * @return \Elastica\Search */ public static function create(SearchableInterface $searchObject) { return $searchObject->createSearch(); }
/** * Returns an slice of the results. * * @param integer $offset The offset. * @param integer $length The length. * * @return array|\Traversable The slice. */ public function getSlice($offset, $length) { return $this->resultSet = $this->searchable->search($this->query, array('from' => $offset, 'size' => $length)); }
/** * @param \Elastica\Query $query * * @return \Elastica\ResultSet */ protected function executeQuery($query) { $rawSearchResult = $this->searchableInterface->search($query); return $rawSearchResult; }