MyBB Community Forums

Full Version: custom search query?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm wondering if there is any way to do custom searches on forum. I mean to make custom SQL query (on threads) and display the result like regular search. Is it possible to achieve by using hooks or I have to create new page and handle whole search by myself?
What's an example query?
eg.
SELECT * FROM `mybb_threads` WHERE `views` > 20
That's already part of advanced search options so just look at the form and make sure the query is done with the correct variables. You could easily do this with only a template change.
Would you mind telling me how to do it? As I see the source of search.php file there is no information about the views.
$search_data = array(
		"keywords" => $mybb->input['keywords'],
		"author" => $mybb->input['author'],
		"postthread" => $mybb->input['postthread'],
		"matchusername" => $mybb->input['matchusername'],
		"postdate" => $mybb->input['postdate'],
		"pddir" => $mybb->input['pddir'],
		"forums" => $mybb->input['forums'],
		"findthreadst" => $mybb->input['findthreadst'],
		"numreplies" => $mybb->input['numreplies']
	);

All in all the example wasn't good. I'd like to search for threads which have attributes stored in separated table.
Eg.
SELECT * FROM threads LEFT JOIN table ON threads.tid = table.tid WHERE attr = "sth"
Or something like that. What's more I'd like to redirect to search results by link. I see that it would be hard to achieve because form data is sent by POST.
Apologies. I saw replies not views.

Yes you'll need custom changes. Either as a plugin or core file edits. You might be better off making a viewsearch.php page based on the search.php page and just use the code you need with a couple minor adjustments for your query.
Thanks. I didn't come up with the idea of copying search.php. It seems to be good solution.
I've done that in the past with better success than just trying to manipulate the existing search.php.
No need to copy search.php if you want it to display and behave exactly like search.php would. See how search results are stored in the DB, either by adding a debug message in search.php before the insert query, or by looking at the DB directly. It looks more complicated than it is. Produce a result set yourself in a plugin, then have search.php display that result set for you.
From what I recall the way the hooks work in search.php makes what you describe more difficult than it should be. If more hooks were in place I think it's possible but those hooks are missing.
Pages: 1 2