MyBB Community Forums

Full Version: Search with two keywords
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What do I have to do to be able to search for 2 keywords. The way I think it is coded now (by looking at the sql string in debug mode), it searches for one or the other but I want them both in the topic/post.

I have looked at the code of search.php and there I found this:
if($mybb->input['keywords']) {
	$wheresql = "(1=0 ";
	if($mybb->input['srchtype'] != 2)
	{
		$words = explode(" ", $mybb->input['keywords']);
		$wordcount = count($words);
		for($i=0;$i<$wordcount;$i++)
		{
			$wheresql .= "OR $op $lookin LIKE '%".addslashes($words[$i])."%'";
			if($lookin2)
			{
				$wheresql .= "OR $op $lookin2 LIKE '%".addslashes($words[$i])."%'";
			}
		}
	}
	else
	{
		$wheresql .=  " AND $lookin LIKE '%".addslashes($mybb->input['keywords'])."%'";
	}
}
It seems that if the variable $mybb->input['srchtype'] equals 2 it uses an and operator in the sql string. But "WHERE 1=0 AND $lookin LIKE '%keywords%'" will never return any results.

If this is possible without changing the code, could anyone tell me how?
If this is not possible consider this post a suggestion.
It will be available in the next mayor version MyBB 1.2 which is able to use the fulltext search of MySQL.
Ok, thanks
It appears the search still uses the OR operator, when I search for this topic (keywords: Search with keywords) and select "search titles only", I get topics like "Search in threads", "Search and strlen not working right" and "Custom links next to search ..". None of which have the keyword "keywords" or the keyword "with" in the title.

I would really like to be able to search for multiple keywords.
I got these results when searching for "Search with keywords" (without "") in titles:

Search and strlen not working right
Search in threads
Search with two keywords
Custom links next to search ..
I search hiphop style theme

Are you sure you didn't get that?
Yes, but it was a bit further down because of last post time.

But the point I tried to make was that I got results that shouldn't be there if the search used the AND operator. I think it is very essential to be able to search on multiple keywords.