ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Searching without keywords

August 12, 2010 8:07pm

Subscribe [3]
  • #1 / Aug 12, 2010 8:07pm

    The site I’m building requires two ways to filter results—by category and by keyword search.  Users should be able to use either or both methods.  Unfortunately EE’s search module requires keywords in order to run.  If not keywords are supplied then we get this error: “You did not submit a search term”.

    It’s the result of this block of code in the search module:

    /** ----------------------------------------
            /**  Did the user submit any keywords?
            /** ----------------------------------------*/
            
            // We only require a keyword if the member name field is blank
            
            if ( ! isset($_GET['mbr']) OR ! is_numeric($_GET['mbr']))
            {        
                if ( ! isset($_POST['member_name']) OR $_POST['member_name'] == '')
                {        
                    if ( ! isset($_POST['keywords']) OR $_POST['keywords'] == "")
                    {            
                        return $this->EE->output->show_user_error('general', array($this->EE->lang->line('search_no_keywords')));
                    }
                }
            }

    I’m reluctant to mess around in here too much—there must be a supported way of searching just on categories, right?

  • #2 / Aug 12, 2010 8:23pm

    Rob Allen

    3105 posts

    For filtering without keywords look at using Dynamic parameters, that will allow you to have a single category drop down without a keywords field.

  • #3 / Aug 12, 2010 8:34pm

    Fantastic, thank you.  I hadn’t seen those before.

    The one thing I don’t think it gets around is the ability to search multiple fields, like find ‘foo’ in title OR body.  Do you know if that’s possible?

  • #4 / Aug 12, 2010 8:45pm

    After a bit more digging I found that setting

    <input type="hidden" name="member_name" value="">

    tricked EE into thinking I was doing a member search and ignoring the keyword requirements.  Thanks for your suggestion, though.

  • #5 / Aug 13, 2010 9:31am

    Sue Crocker

    26054 posts

    Thanks for the assist, bluedreamer. Alex, glad you have a solution.

    Don’t hesitate to post again as needed.

  • #6 / Aug 13, 2010 9:44am

    Ingmar

    29245 posts

    Closing on Sue’s behalf, as it were.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases