News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Category-specific search?

Started by Shotster, December 04, 2009, 07:59:32 PM

Previous topic - Next topic

Shotster

That's what I thought. Not a good theory in my experience.  :)

-Steve

Arantor

Guess we have a different experience... though I have to say that I as a user haven't needed it either.

But we can't do things unless people tell us they want them, really.

Shotster

Quote from: Arantor on December 04, 2009, 09:41:23 PMYou'll have to send the category through, then pick it up in Search.php, to do a query to find all the boards that live in a given category, and add that into the search query.

That's pretty much what I did, and in my [admittedly limited] testing, it seems to work. I don't have time to learn how to create a packaged mod, so if anyone finds cat-specific searching useful and is interested in modding the mod, here's the relevant section of Search.php...

// ******** Below taken from Search Focus Dropdown mod with changes by Shotster ***************

$s_scope = isset($_REQUEST['search_scope']) ? $_REQUEST['search_scope'] : '';

// If search scope is category...
if ($s_scope == 'cat') {

    // Change scope to board.
    $_REQUEST['search_scope'] = $s_scope = 'board';

    // Get ids of boards in category.
    $request = $smcFunc['db_query'](
        'order_by_board_order', '
        SELECT id_board
        FROM {db_prefix}boards
        WHERE id_cat='.$_REQUEST['cat'],
        array()
    );

    // Stuff the board id's into the array.
    $_REQUEST['brd'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {

        array_push($_REQUEST['brd'], $row['id_board']);
    }
    $smcFunc['db_free_result']($request);
}

// if search focus is set to "all" or "topic" (not "board" or ""), unset the 'brd' variable
if ( isset($_REQUEST['brd']) && (($s_scope == "all") || ($s_scope == "topic")) ) {

    unset($GLOBALS['_REQUEST']['brd']);
    // if focus is "all", also unset the $context['current_board'] variable
    if ( isset($context['current_board']) && ($s_scope == "all") )
        unset($GLOBALS['context']['current_board']);
}

// if search focus is not set to "topic", unset the 'topic' variable
if ( isset($_REQUEST['topic']) && ($s_scope <> "topic") ) {

    unset($GLOBALS['_REQUEST']['topic']);
    // also unset the $context['current_topic'] variable
    if ( isset($context['current_topic']) )
        unset($GLOBALS['context']['current_topic']);
}

// if searching "entire forum", remove the board+category links already added to the linktree
if ($s_scope == "all") {

    array_pop($context['linktree']);
    array_pop($context['linktree']);
}
// ********************************************************************************************

-Steve

Arantor

Looks good there. I'd suggest it be added to the mod rather than being packaged as another/separate mod.

Might be worth posting in the mod's thread directing them here, actually...

Advertisement: