|
| |
|
|
revsof
Posts: 7 Joined: 1/1/2008 Status: offline
|
Search XML - Return Results - 3/27/2008 17:18:04
Hello, I am building a Joomla based site and what I am trying to do is use the search component included in Joomla to search an .xml database I have and return only applicable results. I have included the code form both of the search components php files below. Here is a sample of the code from the xml database: <Row number="1"><Cell colname="ItemNumber" idx="1"><Data>Item Number</Data></Cell><Cell colname="Description" idx="2"><Data>Description</Data></Cell><Cell colname="CommonName" idx="3"><Data>Common Name</Data></Cell><Cell colname="Height" idx="4"><Data>Height</Data></Cell><Cell colname="Spread" idx="5"><Data>Spread</Data></Cell><Cell colname="Zone" idx="6"><Data>Zone</Data></Cell><Cell colname="Notes" idx="7"><Data>Notes</Data></Cell><Cell colname="Price6" idx="8"><Data>Price 6</Data></Cell> <Row number="2"><Cell colname="ItemNumber" idx="1"><Data>Z2ADIPE4PT</Data></Cell><Cell colname="Description" idx="2"><Data>Adiantum pedatum</Data></Cell><Cell colname="CommonName" idx="3"><Data>Maidenhair Fern</Data></Cell><Cell colname="Height" idx="4"><Data>H:60cm</Data></Cell><Cell colname="Spread" idx="5"><Data>S:60cm</Data></Cell><Cell colname="Zone" idx="6"><Data>Z:2</Data></Cell><Cell colname="Notes" idx="7"><Data>Provide a shaded growing area with rich well drained soil. The fronds supported by nearly black stems and provides a display of yellow fall foliage.</Data></Cell><Cell colname="Price6" idx="8"><Data>$7.3700</Data></Cell> I am optimistic that there is a way to modify the code in Joomla's search.php file to tell it to search the .xml file and then return the 5 or 6 results only. The database has approx. 1500 entrys like the 2 above so it is necessary to only have the search display the relevant ones. If anyone has any ideas or can make this happen please let me know. I am able to style the database myself, just cant make it work lol. Here is the code from search.html.php: <?php /** * @version $Id: search.html.php,v 1.1.1.1 2006/07/13 19:59:31 rcho Exp $ * @package Joomla * @subpackage Search * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined( '_VALID_MOS' ) or die( 'Restricted access' ); /** * @package Joomla * @subpackage Search */ class search_html { function openhtml( $params ) { if ( $params->get( 'page_title' ) ) { ?> <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>"> <?php echo $params->get( 'header' ); ?> </div> <?php } } function searchbox( $searchword, &$lists, $params ) { global $Itemid; ?> <form action="index.php" method="get"> <input type="hidden" name="option" value="com_search" /> <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" /> <table class="contentpaneopen<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr> <td nowrap="nowrap"> <label for="search_searchword"> <?php echo _PROMPT_KEYWORD; ?>: </label> </td> <td nowrap="nowrap"> <input type="text" name="searchword" id="search_searchword" size="30" maxlength="20" value="<?php echo stripslashes($searchword);?>" class="inputbox" /> </td> <td width="100%" nowrap="nowrap"> <input type="submit" name="submit" value="<?php echo _SEARCH_TITLE;?>" class="button" /> </td> </tr> <tr> <td colspan="3"> <?php echo $lists['searchphrase']; ?> </td> </tr> <tr> <td colspan="3"> <label for="search_ordering"> <?php echo _CMN_ORDERING;?>: </label> <?php echo $lists['ordering'];?> </td> </tr> </table> </form> <?php } function searchintro( $searchword, $params ) { ?> <table class="searchintro<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr> <td colspan="3" align="left"> <?php echo _PROMPT_KEYWORD . ' <b>' . stripslashes($searchword) . '</b>'; ?> <?php } function message( $message, $params ) { ?> <table class="searchintro<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr> <td colspan="3" align="left"> <?php eval ('echo "'.$message.'";'); ?> </td> </tr> </table> <?php } function displaynoresult() { ?> </td> </tr> <?php } function display( &$rows, $params, $pageNav, $limitstart, $limit, $total, $totalRows, $searchword ) { global $mosConfig_hideCreateDate; global $mosConfig_live_site, $option, $Itemid; $c = count ($rows); $image = mosAdminMenus::ImageCheck( 'google.png', '/images/M_images/', NULL, NULL, 'Google', 'Google', 1 ); $searchword = urldecode( $searchword ); // number of matches found echo '<br/>'; eval ('echo "'._CONCLUSION.'";'); ?> <a href="http://www.google.com/search?q=<?php echo $searchword; ?>" target="_blank"> <?php echo $image; ?></a> </td> </tr> </table> <br /> <div align="center"> <?php echo $pageNav->writePagesCounter(); $searchphrase = strtolower( strval( mosGetParam( $_REQUEST, 'searchphrase', 'all' ) ) ); $ordering = strtolower( strval( mosGetParam( $_REQUEST, 'ordering', 'newest' ) ) ); $link = $mosConfig_live_site ."/index.php?option=$option&Itemid=$Itemid&searchword=$searchword&searchphrase=$searchphrase&ordering=$ordering"; echo $pageNav->getLimitBox( $link ); ?> </div> <table class="contentpaneopen<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr class="<?php echo $params->get( 'pageclass_sfx' ); ?>"> <td> <?php $z = $limitstart + 1; $end = $limit + $z; if ( $end > $total ) { $end = $total + 1; } for( $i=$z; $i < $end; $i++ ) { $row = $rows[$i-1]; if ($row->created) { $created = mosFormatDate ($row->created, _DATE_FORMAT_LC); } else { $created = ''; } ?> <fieldset> <div> <span class="small<?php echo $params->get( 'pageclass_sfx' ); ?>"> <?php echo $i.'. ';?> </span> <?php if ( $row->href ) { $row->href = ampReplace( $row->href ); if ($row->browsernav == 1 ) { ?> <a href="<?php echo sefRelToAbs($row->href); ?>" target="_blank"> <?php } else { ?> <a href="<?php echo sefRelToAbs($row->href); ?>"> <?php } } echo $row->title; if ( $row->href ) { ?> </a> <?php } if ( $row->section ) { ?> <br/> <span class="small<?php echo $params->get( 'pageclass_sfx' ); ?>"> (<?php echo $row->section; ?>) </span> <?php } ?> </div> <div> <?php echo ampReplace( $row->text );?> </div> <?php if ( !$mosConfig_hideCreateDate ) { ?> <div class="small<?php echo $params->get( 'pageclass_sfx' ); ?>"> <?php echo $created; ?> </div> <?php } ?> </fieldset> <br/> <?php } ?> </td> <?php } function conclusion( $searchword, $pageNav ) { global $mosConfig_live_site, $option, $Itemid; $searchphrase = strtolower( strval( mosGetParam( $_REQUEST, 'searchphrase', 'all' ) ) ); $ordering = strtolower( strval( mosGetParam( $_REQUEST, 'ordering', 'newest' ) ) ); $link = $mosConfig_live_site ."/index.php?option=$option&Itemid=$Itemid&searchword=$searchword&searchphrase=$searchphrase&ordering=$ordering"; ?> <tr> <td colspan="3"> <div align="center"> <?php echo $pageNav->writePagesLinks( $link ); ?> </div> </td> </tr> </table> <?php } } ?> And here is the code from search.php: <?php /** * @version $Id: search.php,v 1.1.1.1 2006/07/13 19:59:31 rcho Exp $ * @package Joomla * @subpackage Search * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined( '_VALID_MOS' ) or die( 'Restricted access' ); require_once( $mainframe->getPath( 'front_html' ) ); // page title $mainframe->setPageTitle( _SEARCH_TITLE ); switch ( $task ) { default: viewSearch(); break; } function viewSearch() { global $mainframe, $mosConfig_absolute_path, $mosConfig_lang, $my; global $Itemid, $database, $_MAMBOTS; global $mosConfig_list_limit; $restriction = 0; // try to find search component's Itemid $query = "SELECT id" . "\n FROM #__menu" . "\n WHERE type = 'components'" . "\n AND published = 1" . "\n AND link = 'index.php?option=com_search'" ; $database->setQuery( $query ); $_Itemid = $database->loadResult(); if ($_Itemid != "") { $Itemid = $_Itemid; } $gid = $my->gid; // Adds parameter handling if( $Itemid > 0 && $Itemid != 99999999 ) { $menu = $mainframe->get( 'menu' ); $params = new mosParameters( $menu->params ); $params->def( 'page_title', 1 ); $params->def( 'pageclass_sfx', '' ); $params->def( 'header', $menu->name, _SEARCH_TITLE ); $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); } else { $params = new mosParameters(''); $params->def( 'page_title', 1 ); $params->def( 'pageclass_sfx', '' ); $params->def( 'header', _SEARCH_TITLE ); $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); } // html output search_html::openhtml( $params ); $searchword = strval( mosGetParam( $_REQUEST, 'searchword', '' ) ); $searchword = $database->getEscaped( trim( $searchword ) ); // limit searchword to 20 characters if ( strlen( $searchword ) > 20 ) { $searchword = substr( $searchword, 0, 19 ); $restriction = 1; } // searchword must contain a minimum of 3 characters if ( $searchword && strlen( $searchword ) < 3 ) { $searchword = ''; $restriction = 1; } $search_ignore = array(); @include "$mosConfig_absolute_path/language/$mosConfig_lang.ignore.php"; $orders = array(); $orders[] = mosHTML::makeOption( 'newest', _SEARCH_NEWEST ); $orders[] = mosHTML::makeOption( 'oldest', _SEARCH_OLDEST ); $orders[] = mosHTML::makeOption( 'popular', _SEARCH_POPULAR ); $orders[] = mosHTML::makeOption( 'alpha', _SEARCH_ALPHABETICAL ); $orders[] = mosHTML::makeOption( 'category', _SEARCH_CATEGORY ); $ordering = strtolower( strval( mosGetParam( $_REQUEST, 'ordering', 'newest') ) ); $lists = array(); $lists['ordering'] = mosHTML::selectList( $orders, 'ordering', 'id="search_ordering" class="inputbox"', 'value', 'text', $ordering ); $searchphrase = strtolower( strval( mosGetParam( $_REQUEST, 'searchphrase', 'any' ) ) ); $searchphrases = array(); $phrase = new stdClass(); $phrase->value = 'all'; $phrase->text = _SEARCH_ANYWORDS; $searchphrases[] = $phrase; $phrase = new stdClass(); $phrase->value = 'all'; $phrase->text = _SEARCH_ALLWORDS; $searchphrases[] = $phrase; $phrase = new stdClass(); $phrase->value = 'exact'; $phrase->text = _SEARCH_PHRASE; $searchphrases[] = $phrase; $lists['searchphrase']= mosHTML::radioList( $searchphrases, 'searchphrase', '', $searchphrase ); // html output search_html::searchbox( htmlspecialchars( stripslashes( $searchword ) ), $lists, $params ); if (!$searchword) { if ( count( $_POST ) ) { // html output // no matches found search_html::message( _NOKEYWORD, $params ); } else if ( $restriction ) { // html output search_html::message( _SEARCH_MESSAGE, $params ); } } else if ( in_array( $searchword, $search_ignore ) ) { // html output search_html::message( _IGNOREKEYWORD, $params ); } else { // html output if ( $restriction ) { // html output search_html::message( _SEARCH_MESSAGE, $params ); } $searchword_clean = htmlspecialchars( stripslashes( $searchword ) ); search_html::searchintro( $searchword_clean, $params ); mosLogSearch( $searchword ); $phrase = strval( mosGetParam( $_REQUEST, 'searchphrase', '' ) ); $ordering = strval( mosGetParam( $_REQUEST, 'ordering', '' ) ); $_MAMBOTS->loadBotGroup( 'search' ); $results = $_MAMBOTS->trigger( 'onSearch', array( $searchword, $phrase, $ordering ) ); $totalRows = 0; $rows = array(); for ($i = 0, $n = count( $results); $i < $n; $i++) { $rows = array_merge( (array)$rows, (array)$results[$i] ); } $totalRows = count( $rows ); for ($i=0; $i < $totalRows; $i++) { $text = &$rows[$i]->text; if ($phrase == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchwords = explode(' ', $searchword); $needle = $searchwords[0]; } $text = mosPrepareSearchContent( $text, 200, $needle ); foreach ($searchwords as $hlword) { $text = preg_replace( '/' . preg_quote( $hlword, '/' ) . '/i', '<span class="highlight">\0</span>', $text ); } if ( strpos( $rows[$i]->href, 'http' ) == false ) { $url = parse_url( $rows[$i]->href ); parse_str( @$url['query'], $link ); // determines Itemid for Content items where itemid has not been included if ( isset($rows[$i]->type) && @$link['task'] == 'view' && isset($link['id']) && !isset($link['Itemid']) ) { $itemid = ''; $_itemid = $mainframe->getItemid( $link['id'], 0 ); if ($_itemid) { $itemid = '&Itemid='. $_itemid; } $rows[$i]->href = $rows[$i]->href . $itemid; } } } $mainframe->setPageTitle( _SEARCH_TITLE ); $total = $totalRows; $limit = intval( mosGetParam( $_GET, 'limit', $mosConfig_list_limit ) ); $limitstart = intval( mosGetParam( $_GET, 'limitstart', 0 ) ); // prepares searchword for proper display in url $searchword_clean = urlencode(stripslashes($searchword_clean)); if ( $n ) { // html output require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); $pageNav = new mosPageNav( $total, $limitstart, $limit ); search_html::display( $rows, $params, $pageNav, $limitstart, $limit, $total, $totalRows, $searchword_clean ); } else { // html output search_html::displaynoresult(); } // html output search_html::conclusion( $searchword_clean, $pageNav ); } // displays back button echo '<br/>'; mosHTML::BackButton ( $params, 0 ); } function mosLogSearch( $search_term ) { global $database; global $mosConfig_enable_log_searches; if ( @$mosConfig_enable_log_searches ) { $query = "SELECT hits" . "\n FROM #__core_log_searches" . "\n WHERE LOWER( search_term ) = '$search_term'" ; $database->setQuery( $query ); $hits = intval( $database->loadResult() ); if ( $hits ) { $query = "UPDATE #__core_log_searches" . "\n SET hits = ( hits + 1 )" . "\n WHERE LOWER( search_term ) = '$search_term'" ; $database->setQuery( $query ); $database->query(); } else { $query = "INSERT INTO #__core_log_searches VALUES ( '$search_term', 1 )" ; $database->setQuery( $query ); $database->query(); } } } ?> Thanks a million, Jon
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|