Created
February 1, 2016 22:05
-
-
Save nsanden/2e54ef2f3207ce84312f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public function performSearches() { | |
$str = 'This is a test only.'; | |
$results = []; | |
$search_types = \app\models\SearchType::find()->orderBy('score DESC')->all(); | |
foreach($search_types as $search_type) { | |
if(count($results) >= $this->max_results) { | |
break; | |
} | |
//exact match query | |
if($search_type->type == self::TYPE_EXACT) { | |
$sql = $this->getExactSql($str, $search_type->field); | |
if($sql) { | |
$search_results = $this->getSearchResults($sql); | |
foreach($search_results as $result) { | |
$results[] = $result; | |
if(count($results) >= $this->max_results) { | |
break; | |
} | |
} | |
} | |
} | |
//keyword match query | |
if($search_type->type == self::TYPE_KEYWORD) { | |
$keywords = $this->getUniqueKeywordsFromString($str); | |
$groups = $this->getUniqueKeywordCombinations($keywords, $search_type->variations); | |
foreach($groups as $group) { | |
$sql = $this->getKeywordsSql($group, $search_type->field, $search_type->variations); | |
if($sql) { | |
$search_results = $this->getSearchResults($sql); | |
foreach($search_results as $result) { | |
$results[] = $result; | |
if(count($results) >= $this->max_results) { | |
break; | |
} | |
} | |
} | |
} | |
} | |
//description match | |
if($search_type->type == self::TYPE_STRING) { | |
//split string up into 100 character array elements | |
if(strlen($str) >= ($search_type->c_size * $search_type->variations)) { | |
$chunks = str_split($str, $search_type->c_size); | |
//split array elements into groups | |
$groups = array_chunk($chunks, $search_type->variations); | |
foreach($groups as $group) { | |
if(strlen(end($group)) >= $search_type->c_size) { //not really sure why this works | |
$sql = $this->getKeywordsSql($group, $search_type->field, $search_type->variations); | |
if($sql) { | |
$search_results = $this->getSearchResults($sql); | |
foreach($search_results as $result) { | |
$results[] = $result; | |
if(count($results) >= $this->max_results) { | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment