Untitled
unknown
plain_text
2 years ago
2.0 kB
6
Indexable
public function getMoreLikeThis($search){ $helper = new Helper(); $indexTags = new ElasticIndex('index_tags'); $query = $this->getQuery('more_like_this', 'query', $search); $tags = $indexTags->search([ 'size'=>10, 'query' => $query, ]); $tags = array_filter($tags, function($tag) use ($search, $helper) { $d = preg_replace('/\s+/', ' ', $helper->removeAccents($tag->descricao)); $s = preg_replace('/\s+/', ' ', $helper->removeAccents($search)); return $d != $s; }); $xtags = $tags; $tags = array_filter($tags, function($tag) use ($search) { return strlen($tag->descricao) > strlen($search); }); if(empty($tags)){ $tags = $xtags; } $tags = array_filter($tags, function($tag) use ($search) { $percent = 0; similar_text($tag->descricao, $search, $percent); return $percent < 90; }); $tags = array_filter($tags, function($tag) use ($search) { $s = preg_replace('/\s+/', ' ', $tag->descricao); $t = explode(" ", $s); return count($t) != 1; }); foreach($tags as $k => $tag){ foreach($tags as $j => $xtag){ if($tag->id == $xtag->id){ continue; } if(!isset($tags[$k])){ continue; } similar_text($tag->descricao, $xtag->descricao, $similarity); if($similarity > 95){ unset($tags[$k]); sort($tags); continue; } } } usort($tags, function($a, $b){ return $a->score < $b->score; }); return array_slice($tags, 0, 3); }
Editor is loading...