MyBB Community Forums

Full Version: [F] Search Bug w/ "and" [R] [C-StefanT]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
You can see in the function that for the full text search the code is altering some keywords like and/or so I think it's just a matter of transfering that part of the code into the standard search if statement.
I decided to go with my first idea, which was to try and remove "and" or "or" from the beginning. I got some friends to test searches here (I just said to come search for help here on MyBB), and not one of them used "and" or "or" at the beginning of their search. So, in theory, removing them totally from the beginning of the search shouldn't impact (at least, too much) on the results.

Nickman and I had a bash at this on MSN - we did have the code right, just in the wrong place.

In the clean_keywords($keywords) function in ./inc/functions_search.php (line 166 start), I think this needs to be added:

	// Search for "and" or "or" and remove if it it's at the beginning
	if(my_strpos($keywords, "or") !== false && my_strpos($keywords, "or") == 0)
	{
		$keywords = substr_replace($keywords, "", 0, 2);
	}
	if(my_strpos($keywords, "and") !== false && my_strpos($keywords, "and") == 0)
	{
		$keywords = substr_replace($keywords, "", 0, 3);
	}

It checks if "and" or "or" is the first word, and simply removes it from the keywords. All other times it is left alone, as the problem occurs only if these words are at the start of the string. Converting it to fulltext signs doesn't seem to work, and neither does escaping it.

For me it returns what I expect it to return in a few test threads, but would be grateful for some other testing! Not sure if it's a good fix, that's up to the boss... Toungue
Isn't the error because there is the missing part in AND () - I think that error should be fixed, not modifying the search input.
Quote:"SELECT t.tid, t.firstpost FROM mybb_threads t WHERE 1=1 AND t.visible >= '0' AND t.closed NOT LIKE 'moved|%' AND ()"
(2009-06-10, 03:19 PM)Ryan Gordon Wrote: [ -> ]Isn't the error because there is the missing part in AND ()

No. As far as I can tell, the error is actually in the perform_search_mysql function (./inc/functions_search.php).

If the word "and" or "or" is in the phrase, it sets it as a boolean. This is also the case when one of these words is the first word. So searching for "and foobar" creates a query like this:

SELECT t.tid, t.firstpost FROM mybb_threads t WHERE 1=1 AND t.visible >= '0' AND t.closed NOT LIKE 'moved|%' AND ( and LOWER(t.subject) LIKE '%foobar%')

That's why I think the words should be stripped from the beginning of the phrase instead of creating lines of code accomodating it when in over 100 searches, not one of the people I asked used them in the beginning of their search. No doubt I'm probably wrong, though...
Ah, I see what your saying now. Yes, your solution makes sense
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group
Pages: 1 2