Interspire Product Knowledge Base

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favorites Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Export to PDF

User Opinions (0 votes)

No users have voted.

How would you rate this answer?



Thank you for rating this answer.

How to add expand the search function to categories

Open up /includes/display/SearchResultsPanel.php

and find:

@usort($completeSearch, compare);

Just BEFORE that line, add in this lot of code:

if(in_array("searchCategories",$_REQUEST["searchWhat"])){

    $pageQuery = sprintf("select DISTINCT(c.CategoryID), c.Name as Title, c.Description as text from %scategories c ",$GLOBALS["AL_CFG"]["tablePrefix"]);

    if($type == 0){ //like search
        $pageQuery .= " where (1=0";
        if(in_array("searchContentBody",$_REQUEST["searchField"])){
            // split the keywords up by either a space or comma as users have different preferences
            $textRay = preg_split("/[\s,]+/",$query,-1, PREG_SPLIT_NO_EMPTY);
            $likeQuery = "";

            $likeQuery .= sprintf(" or c.Description LIKE '%%%s%%' ",$query);
            // generate the LIKE query for all the keywords
            foreach ($textRay as $key=>$value) {

                $likeQuery .= sprintf(" or c.Description LIKE '%%%s%%' ",$value);
            }
            $pageQuery .= $likeQuery;
        }

        if(in_array("searchTitle",$_REQUEST["searchField"])){
            // split the keywords up by either a space or comma as users have different preferences
            $textRay = preg_split("/[\s,]+/",$query,-1, PREG_SPLIT_NO_EMPTY);
            $likeQuery = "";
            $likeQuery .= sprintf(" or c.Name LIKE '%%%s%%' ",$query);

            // generate the LIKE query for all the keywords
            foreach ($textRay as $key=>$value) {
                $likeQuery .= sprintf(" or c.Name LIKE '%%%s%%' ",$value);

            }
            $pageQuery .= $likeQuery;
        }

    }else{ // instr search
        if(in_array("searchContentBody",$_REQUEST["searchField"])){
            $pageQuery .= sprintf(" or INSTR(c.Description,'%s') ",$query);

        }

        if(in_array("searchTitle",$_REQUEST["searchField"])){
            $pageQuery .= sprintf(" or INSTR(c.Name,'%s') ",$query);
        }
    }
    $pageQuery .= ")";

    $query2 = $GLOBALS['AL_DB']->Query($pageQuery);

    while ($row = $GLOBALS['AL_DB']->Fetch($query2)) {
        $row['ResultType'] = 'Category';
        $row['Summary'] = substr(strip_tags($row['text']),0,450);
        if(strlen($row['text']) > 450) $row['Summary'] .= "...";
        $row['Link'] =  AL_HELPER::CategoryLink($row["CategoryID"], $row["Title"]);
        $completeSearch[] = $row;

    }

}


We now need to add it to the form for the advanced search field, you'll need to open: /templates/{your-template}/Default/Panels/AdvancedSearchPanel.html

Find:

<input type="checkbox" name="searchWhat[]" value="searchPages" %%GLOBAL_searchPages%% />
            %%LNG_hpPages%%


And add this:

<input type="checkbox" name="searchWhat[]" value="searchCategories" %%GLOBAL_searchCategories%% /> Categories

Related Articles

No related articles were found.

Attachments

No attachments were found.

Powered by Interspire Knowledge Manager - World's #1 Best Selling FAQ and Knowledge Base Software