Each word in your search query must be at least two characters long.

Started by Biology Forums, August 31, 2014, 04:00:05 PM

Previous topic - Next topic

Biology Forums

I get this error obviously when the word is less than or equal to two characters.

Is there something I could do to 1) prevent this error from showing, and 2) a PHP function that automatically removes smaller words and searching everything else in the search query provided by the user?

Note: I do realize that if the search query is put in quotes, it works fine.

Thank you for reading.

Biology Forums

A little update:

This sort of does what I'm asking, I guess...

http://stackoverflow.com/questions/7695016/remove-short-words-and-characters-from-a-string-in-php

Not sure how to incorporate it here:

foreach ($searchArray as $index => $value)
{
if (($searchArray[$index] = trim($value, '-_\' ')) === '' || in_array($searchArray[$index], $blacklisted_words))
unset($searchArray[$index]);
// Don't allow very, very short words.
elseif (strlen($value) < 2)
{
$context['search_errors']['search_string_small_words'] = true;
unset($searchArray[$index]);
}
else
$searchArray[$index] = addslashes($searchArray[$index]);
}

spiros

Have you managed to resolve this issue? Nice site, by the way.

Doug Heffernan

Quote from: spiros on January 27, 2022, 10:09:53 AMHave you managed to resolve this issue? Nice site, by the way.

Dude, that was a 8 year old post that you bumped ;D

Advertisement: