this is the first time for me asking a question here so please don't crucify me if I didn't do everything 100% correct.
I am trying to create a full text search with php and mysql that returns results that decrease by relevance. The user will type in words to look for in an article, so I don't know how many words he will use. Let' say the user is looking for differnt occupations in an article like
$searchstring = 'painter bricklayer baker pope'
Now first I want to search for texts where ALL these words appear. In the next step I want to widen the search by leaving one word away.
Second search string should then be only
'painter bricklayer baker'
third:
painter bricklayer pope
forth:
painter baker pope
fifth:
bricklayer painter pope
And then the same should happen for all these new variants again, like for the second result:
painter bricklayer
painter baker
bricklayer baker
and then for this variants again and again until there is only one word left.
Here is what I've got so far but it leads to some dead end because I am not able to store all sub-results in separate arrays and do the same to them again and again. But I guess my approach ist totally wrong anyway and there might be a propper solution for this already that I am just not able to find on my own. So, can anyone push me in the right direction please?
`
';
$stringarray = explode( ' ', $searchstring );
$collectionArray = array();
$newString = '';
$run = count($stringarray);
while ($run > 1) {
$length = count($stringarray);
$counter = $length-1;
echo '<br><br>';
echo '$counter: ' . $counter . '<br>';
while ($counter > 0) {
for ($i = $length-1; $i >=0; $i--)
{
echo 'Counter: ' . $counter . ' | Index ' . $i .': ';
if ($i == ($counter)) {
echo '-----<br>';
continue;
}
echo $stringarray[$i] . '<br>';
$newString = $newString . ' ' . $stringarray[$i];
//echo $counter . ' danach';
}
//print_r($collectionArray);
$collectionArray[] = $newString;
$counter--;
$newString = '';
echo '<br><br>';
}
array_pop($stringarray);
print_r($stringarray);
echo '<br>';
print_r($collectionArray);
$run--;
}
?>`