1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding own Thread Search Criteria

Discussion in 'XenForo Development Discussions' started by ragtek, Sep 22, 2011.

  1. ragtek

    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?
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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 &$containerDataXenForo_Template_Abstract $template)
        {
            if (
    $templateName == 'search_form_post')
            {
                
    $content .= 'foobar';
            }
        }
    }
     
    ceribik likes this.
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Or completely replace the template using the template_create event:

    PHP:
    <?php

    class TemplateCreate_Foo
    {
        public static function 
    bar($templateName, array &$paramsXenForo_Template_Abstract $template)
        {
            if (
    $templateName == 'search_form_post')
            {
                
    $templateName 'foobar_template';
            }
        }
    }
     
  4. ragtek

    ragtek Guest

    I don't mean the template part.

    e.g.:
    test.png

    I have a new checkbox with the name "solved_only"

    What now?:D
    What search classes/controllers? need i do edit?
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This is the controller for submitting a new search:

    XenForo_ControllerPublic_Search::actionSearch

    From there you can follow the logic to other classes.
     
    EgyKit likes this.
  6. ragtek

    ragtek Guest

    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:(
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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'));
    		}
    
     
  8. Crispy

    Crispy Member

    Am I being silly or does this replicate functionality of Thread Prefixes?
     
  9. Brogan

    Brogan XenForo Moderator Staff Member

    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.
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
    Brogan likes this.
  11. Brogan

    Brogan XenForo Moderator Staff Member

    Of course.

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

Share This Page