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.

How can I narrow search results using multiple categories?

February 19, 2009 12:46pm

Subscribe [2]
  • #1 / Feb 19, 2009 12:46pm

    Ridge

    44 posts

    I have a form to search recipes. These recipes are categorized in multiple ways. I’d like to offer a user a way to narrow their search results by selecting multiple categories, without having to use the multiple select list (which the audience of this site simply won’t understand).

    Right now I have this:

    {exp:search:simple_form id="recipesearchform" search_in="entries" status="open" where="any" results="10" weblog="recipe-upload"}
    <div>
        <label for="searchrecipes">Search recipes</label>
        <input type="text" class="searchtext" value="" maxlength="100" name="keywords" id="searchrecipes" />
        <input type="image" src="/css/cssimages/button-search.png" class="submit" id="searchrecipessubmit" value="Go" />
    </div>
    <div>
        <select name='cat_id[]'>
            <option value="" selected="selected">Cuisine Type</option>
            {exp:weblog:categories weblog="recipe-upload" style="linear" category_group="6"}<option value="{category_id}">{category_name}</option>
            {/exp:weblog:categories}
        </select>
        <select name='cat_id[]'>
            <option value="" selected="selected">Recipe Category</option>
            {exp:weblog:categories weblog="recipe-upload" style="linear" category_group="2"}<option value="{category_id}">{category_name}</option>
            {/exp:weblog:categories}
        </select>
        <select name='cat_id[]'>
            <option value="" selected="selected">Menu Category</option>
            {exp:weblog:categories weblog="recipe-upload" style="linear" category_group="3"}<option value="{category_id}">{category_name}</option>
            {/exp:weblog:categories}
        </select>
        <select name='cat_id[]'>
            <option value="" selected="selected">Price Range</option>
            {exp:weblog:categories weblog="recipe-upload" style="linear" category_group="7"}<option value="{category_id}">{category_name}</option>
            {/exp:weblog:categories}
        </select>
        <input type="image" src="/css/cssimages/button-search.png" class="submit" id="searchrecipessubmit2" value="Go" />
    </div>
    {/exp:search:simple_form}

    What it’s doing right now is applying the last <select name=“cat_id[]”> parameters to filter the search results (ie by Price Range), and ignoring the other categories. How can I get it to filter by whichever categories the user picks in the dropdowns?

    Thanks!

  • #2 / Feb 19, 2009 12:57pm

    ender

    1644 posts

    sounds like a custom query is going to be the easiest way to do this.

  • #3 / Feb 19, 2009 1:13pm

    Ridge

    44 posts

    Custom queries make my head hurt. 😊 Any pointing in the right direction would be appreciated. 😊

  • #4 / Feb 19, 2009 1:23pm

    ender

    1644 posts

  • #5 / Feb 19, 2009 1:27pm

    lebisol

    2234 posts

    and for windows: SQLyog
    consider using checkboxes vs. select lists and then using query with cat1= x AND cat2=y.

    is “Price Range” set of categories of pre-set prices?
    0-100
    100-500
    500-1000
    kinda thing?

  • #6 / Feb 19, 2009 1:34pm

    Ridge

    44 posts

    Thanks, but I’m afraid this is quickly going over my head. Also, the design dictates a series of select lists, not checkboxes, unfortunately.

    Edited to add: Yes, price range are pre-defined ranges (under $5, $5.01 - $10, etc)

  • #7 / Feb 19, 2009 2:57pm

    lebisol

    2234 posts

    Hi Ridge,
    I don’t know much how the search is built but looking at the documentation there does not seem to be the way to daisy-chain the cat IDs when broken down by category groups.
    I do believe it is possible with custom query but this would also mean that your results page would be custom vs. using results page. Which could be quite a bit of leg work.

  • #8 / Feb 19, 2009 3:09pm

    Ridge

    44 posts

    OK, well as I don’t know enough about custom queries to attempt this (and certainly not with the deadline for this site fast approaching) I guess I’ll have to table this, unless anyone can offer a suggestion/extension/plugin that would help.

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

ExpressionEngine News!

#eecms, #events, #releases