Adding own Thread Search Criteria

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
I've created a new field for threads (solved) which is 0 or 1.

I've also overwritten several classes ( the thread/post? search handler & datawriter), to input the additional field to the meta data

How can i create now a checkbox / option, which will be included into the search?
 
The search_bar template has a hook you can use:

Code:
<xen:hook name="quick_search">

But the full search forms (search_form and search_form_post) don't contain any hooks. Nor do I see any convenient params that could be used for this purpose.

One option is to create a listener for template_post_render and hack away at the html. This callback demonstrates how you can modify the final output:

PHP:
<?php

class TemplatePostRender_Foo
{
	public static function bar($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template)
	{
		if ($templateName == 'search_form_post')
		{
			$content .= 'foobar';
		}
	}
}
 
Or completely replace the template using the template_create event:

PHP:
<?php

class TemplateCreate_Foo
{
	public static function bar($templateName, array &$params, XenForo_Template_Abstract $template)
	{
		if ($templateName == 'search_form_post')
		{
			$templateName = 'foobar_template';
		}
	}
}
 
I don't mean the template part.

e.g.:
test.webp

I have a new checkbox with the name "solved_only"

What now?:D
What search classes/controllers? need i do edit?
 
This is the controller for submitting a new search:

XenForo_ControllerPublic_Search::actionSearch

From there you can follow the logic to other classes.
 
I've added all this stuff, but it's never included into the search query:(

1. thread search handler:

PHP:
    public function getTypeConstraintsFromInput(XenForo_Input $input)
       {
           $constraints = array();

           $notSolved = $input->filterSingle('not_solved', XenForo_Input::UINT);
           if ($notSolved)
           {
               $constraints['not_solved'] = true;
           }

           return $constraints;
       }

    public function processConstraint(XenForo_Search_SourceHandler_Abstract $sourceHandler, $constraint, $constraintInfo, array $constraints)
       {
           die('da');
           if ($constraint == 'not_solved')
           {

                   return array(
                       'query' => array('thread', 'is_solved', '=', 0)
                   );
               
           }

           return false;
       }

BUT it seems that the thread search handler isn't called if i'm in http://xenforo.com/community/search/?type=post (because type is set to post:D )
i'll move this to post and try it again

2. problem is, that i need a keyword:(
It's not possible to use only a checkbox or date:(
 
2. problem is, that i need a keyword:(
It's not possible to use only a checkbox or date:(

That requirement is from this code in the controller:

Code:
		if ($input['keywords'] === '' && empty($constraints['user']))
		{
			// must have keyword or user constraint
			return $this->responseError(new XenForo_Phrase('please_specify_search_query_or_name_of_member'));
		}
 
Or completely replace the template using the template_create event:
Is this a viable option for those templates which don't contain hooks?

I'm in the process of converting all of my template modifications into add-ons, and in some cases there isn't a hook available.
 
Is this a viable option for those templates which don't contain hooks?

I'm in the process of converting all of my template modifications into add-ons, and in some cases there isn't a hook available.

It's an option, but not really a better option. It suffers from the same problem as template modifications in that you need to update them when you upgrade.
 
Of course.

And without the template being marked as outdated, it wouldn't be immediately obvious that it had changed.
 
Top Bottom