Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A Stab In The Dark Asking This...
Old 08-23-2007, 03:36 PM A Stab In The Dark Asking This...
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 961
Name: Darren
Location: England
Trades: 0
But Here Goes...

Please have a look at the script im trying to mod.

At the moment, the "zipcode" search will only return listings if they are an exact match. As im converting to UK Postcodes that would be something like HP19 7QJ.

I need it to be able to use a partial match and pick up on the "HP" or 1st two letters of the search to return all results in that area.

I think this is the page that does all the searching...

Code:
<?php

/* *********************************************************************
*
*   This script is owned and copyrighted by phpMyDirectory.com. Your
*  license confers  no  title  or ownership in the Software and is
*  not a sale of any rights to the Software.
*
***********************************************************************/

function cleanSearchInput($string, $min_length=NULL) {
    $string = trim($string);
    $string = substr ( $string, 0, 64 );
    $string = str_replace ( ","," ",$string );
    $string = str_replace ( " +"," ",$string );
    $string = ereg_replace ( "[[:space:]]", " ", $string );

    if($string == "") return "";

    if(!is_null($min_length)) {
        $word_array = explode(' ',$string);
        foreach($word_array as $key=>$value) {
            if ( strlen ( $value ) > $min_length ){
                $final_string .= $value.' ';
            }
        }
        return rtrim($final_string);
    }
    return $string;
}                                                               

function getFullTextComponentSearchQuery($keywords, $component_title, $component_table, $get_count=false, $limit_start=NULL, $limit_amount=NULL) {
    if($get_count) {
        $query .='SELECT COUNT(*) as count';
    } else {
        $query .='SELECT *';
    }

    if($keywords != '' AND $get_count == false) {
        $words = '\''.$keywords.'\'';

        $query .=', 
                 MATCH (item,message) 
                 AGAINST ('.$words.') 
                 AS score';
    }
    
    $query .=  ' FROM '.$component_table.' INNER JOIN '.T_LISTINGS.' ON '.$component_table.'.firmselector='.T_LISTINGS.'.selector WHERE';
    
    if($keywords != '') {
        $words = '\''.$keywords.'\'';          
        $query .= ' MATCH (item,message)
                   AGAINST ('.$words.') AND';
    }
    
    $query_where .= ' '.T_LISTINGS.'.date_expire > NOW() AND admin_approved=1';
    
    $query .= $query_where;

    $query .= ' ORDER BY membership DESC';
    
    if(!is_null($limit_start)) {
        $query .= ' LIMIT '.$limit_start.', '.$limit_amount.' ';
    }
        
    return $query;    
}


include('./defaults.php' );
include('./includes/functions_paginate.php');

$incomingline = $lang['search'];

if ( $_GET['keyword'] <> '' ) {
	$keywords = rawurldecode ( $_GET['keyword'] );
} else {
	$keywords = $_POST['keyword'];
}

if ( $_GET['type'] <> '' ) {
    $type = rawurldecode ( $_GET['type'] );
} else {
    $type = $_POST['type'];
}

$title = $lang[$type];

if($type == 'products') {
    $component_table = T_PRODUCTS;    
} elseif ($type == 'documents') {
    $component_table = T_DOCUMENTS;
} elseif ($type == 'images') {
    $component_table = T_IMAGES;
}

                           
$page = declare_page($_GET['page']);
$page_start = get_page_start($page,$config['count_search']);

$keywords = cleanSearchInput($keywords,2);

$r_count = $db->GetRow(getFullTextComponentSearchQuery($keywords,$component_title,$component_table,true,NULL,NULL));
if($results_amount = $r_count['count']) {
    $r = $db->Execute(getFullTextComponentSearchQuery($keywords,$component_title,$component_table,false,$page_start,$config['count_search']));
}


$fetchcounter = $config['count_search'];

$sdate1 = date("H:i:s");
$sdate2 = date("Y-m-d");
$sdate3 = undate($sdate2, $config['date_type']);

if($config['search_require_values'] == "YES" AND trim($sstring) == "" AND $zip == "") {
    $results_amount = 0;
    $fetchcounter = 0;    
}
ob_start();
?>
 <br>
  <div align="left"><span class="text">
    &nbsp;&nbsp;&nbsp;<?php echo $incomingline.' '.$title.' </span><span class="text_bold">( '.$original_string.' )</span>
     <span class="text">&nbsp;&nbsp;['.$lang['results'].': </span><span class="text_bold">'.$results_amount.'</span><span class="text"> // [ '.$sdate1.', '.$sdate3.' ]]'; ?></span><br>
  </div>
 <br>

<?php
                                      

if ( $results_amount == 0 AND $config['search_require_values'] == "YES" AND trim($sstring) == "") {
	echo "<span class=text>".$lang['nothing_found2']."</span><br><br><a href=\"javascript:history.back()\">".$lang['back']."</a>";    
} elseif($results_amount == 0) {
	echo "<span class=text>".$lang['nothing_found']."</span><br><br><a href=\"javascript:history.back()\">".$lang['back']."</a>";
} else {
    include (PMDROOT . "/includes/template_listing_results.php");
}

if ( $results_amount > $config['count_search'] ) {
    $keywordencoded = urlencode($_GET['keyword']);
    $catencoded = urlencode($_GET['category']);
    $locencoded = urlencode($_GET['location']);
    $zipcoded = urlencode($_GET['zip']);
    if ($config['mod_rewrite'] == "YES") {
 		echo paginate($results_amount, $config['count_search'], 25, $page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], "search-component.php?keyword=$keywordencoded&location=$locencoded&category=$catencoded&zip=$zipcoded");
 	}
 	else{
 		echo paginate($results_amount, $config['count_search'], 25, $page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], "search-component.php?keyword=$keywordencoded&location=$locencoded&category=$catencoded&zip=$zipcoded");
 	}
	echo "<br><br>";
}
$listing_results = ob_get_contents();
ob_end_clean();

$template_content = & new PMDTemplate(PMDROOT.TEMPLATE_PATH.'search-component.tpl');
$template_content->set('listing_results',$listing_results);

include(PMDROOT.'/includes/template_setup.php');
?>
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-23-2007, 04:07 PM Re: A Stab In The Dark Asking This...
Extreme Talker

Posts: 182
Trades: 0
Wow, mysql full text search is new to me. I just did some googling and learned quite a bit. I think i found the answer to your problem though.

Are you sure this is the page that searches for the zipcode? If so...

Try adding an asterisk to this code snippet here:
PHP Code:

AGAINST 
('.$words.'
to make it:
PHP Code:

AGAINST 
('.$words.'*) 
it may even be able to do something like this:
PHP Code:

AGAINST 
(*'.$words.'*) 
Play around with it and see. I've never done a full text search before so I can't be certain this is syntactically correct.




'apple*'

Find rows that contain words such as “apple”, “apples”, “applesauce”, or “applet”.


This page has documentation on full text searches:
http://dev.mysql.com/doc/refman/5.0/...t-boolean.html

Last edited by bhgchris; 08-23-2007 at 04:08 PM..
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 04:29 PM Re: A Stab In The Dark Asking This...
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 961
Name: Darren
Location: England
Trades: 0
hmmm, didn't work but ive notice that when you hit the search button it calls up search-all.php so might be in there?

Code:
<?php

/* *********************************************************************
*
*   This script is owned and copyrighted by phpMyDirectory.com. Your
*  license confers  no  title  or ownership in the Software and is
*  not a sale of any rights to the Software.
*
***********************************************************************/

include('./defaults.php' );
include('./includes/functions_search.php');
include('./includes/functions_paginate.php');

$incomingline = $lang['search'];

if ( $_GET['keyword'] <> '' ) {
	$keywords = rawurldecode ( $_GET['keyword'] );
} else {
	$keywords = $_POST['keyword'];
}

if ( $_GET['location'] <> '' ) {
    $location = ' '.rawurldecode ( $_GET['location'] );
} else {
    $location = ' '.$_POST['location'];
}

if ( $_GET['category'] <> '' ) {
    $category = ' '.rawurldecode ( $_GET['category'] );
} else {
    $category = ' '.$_POST['category'];
}

if ( $_GET['zip_miles'] <> '' ) {
    $zip_miles = rawurldecode ( $_GET['zip_miles'] );
} else {
    $zip_miles = $_POST['zip_miles'];
}

if ( $_GET['boolean_type'] <> '' ) {
    $boolean_type = rawurldecode ( $_GET['boolean_type'] );
} else {
    $boolean_type = $_POST['boolean_type'];
}

if(trim($boolean_type) == "") {
    $boolean_type = 'AND';
} 

if ( $_GET['zip'] <> '' ) {
    $zip = rawurldecode ( $_GET['zip'] );
} else {
    $zip = $_POST['zip'];
}

$original_string = $keywords.$location.$category.' '.$zip;

if ( $_GET['address'] <> '' ) {
    $other_search_fields['listing_address1'] = cleanSearchInput(rawurldecode($_GET['address']),1);
    $original_string .= ' '.$other_search_fields['listing_address1'];
} elseif ($_POST['address'] <> '') {
    $other_search_fields['listing_address1'] = cleanSearchInput($_POST['address'],1);
    $original_string .= ' '.$other_search_fields['listing_address1'];
}

if($zip_miles != "" AND $zip != "") {
    include("./modules/custom/Zip_Code_Radius/includes/phpZipLocator.php");
    $zipLoc = new zipLocator;
    
    $zipArray = $zipLoc->inradius($zip,$zip_miles);
} elseif($zip != "") {
    $zipArray[] = $zip;
}
                           
$page = declare_page($_GET['page']);
$page_start = get_page_start($page,$config['count_search']);

if(version_compare(mysql_get_server_info(),'4.1.1') >= 0) {
    $query_expansion = true;
} else {
    $query_expansion = false;
}

if(version_compare(mysql_get_server_info(),'4.0.1') >= 0) {
    $boolean_mode = true;
} else {
    $boolean_mode = false;
}

$sstring = cleanSearchInput($keywords,3).' '.cleanSearchInput($location,3).' '.cleanSearchInput($category,3);

if($boolean_mode) {
    //$sstring = cleanSearchInput($sstring);                       
    $r_count = $db->GetRow(getFullTextBooleanSearchQuery($sstring,$zipArray,$other_search_fields,$boolean_type,true,NULL,NULL, $query_expansion));
    if($results_amount = $r_count['count']) {
        $r = $db->Execute(getFullTextBooleanSearchQuery($sstring,$zipArray,$other_search_fields,$boolean_type,false,$page_start,$config['count_search'], $query_expansion));
    }
} else {
    //$sstring = cleanSearchInput($sstring);
    
    $r_count = $db->GetRow(getFullTextSearchQuery($sstring,$zipArray,$other_search_fields,$boolean_type,NULL,NULL, $query_expansion));
    if($results_amount = $r_count['count']) {
        $r = $db->Execute(getFullTextSearchQuery($sstring,$zipArray,$other_search_fields,$boolean_type,$page_start,$config['count_search'], $query_expansion));
    }    
    
}

if($results_amount == 0) {
    $keywords = cleanSearchInput($keywords,2);
    $location = cleanSearchInput($location,2);
    $category = cleanSearchInput($category,2);
    
    $r_count = $db->GetRow(getLikeSearchQuery($keywords, $location, $category, $zipArray, $other_search_fields, $boolean_type, true,NULL,NULL));
    if($results_amount = $r_count['count']) {
        $r = $db->Execute(getLikeSearchQuery($keywords, $location, $category, $zipArray, $other_search_fields, $boolean_type, false,$page_start,$config['count_search']));
    }
}

$fetchcounter = $config['count_search'];


if($config['search_require_values'] == "YES" AND trim($sstring) == "" AND $zip == "") {
    $results_amount = 0;
    $fetchcounter = 0;    
}
ob_start();
?>
 <br>
  <div align="left"><span class="text">
    &nbsp;&nbsp;&nbsp;<?php echo "$incomingline <b>( $original_string )</b>
     &nbsp;&nbsp;".$lang['results'].": <b>$results_amount</b>"; ?></span><br>
  </div>
 <br>

<?php
                                      

if ( $results_amount == 0 AND $config['search_require_values'] == "YES" AND trim($sstring) == "") {
	echo "<span class=text>".$lang['nothing_found2']."</span><br><br><a href=\"javascript:history.back()\">".$lang['back']."</a>";    
} elseif($results_amount == 0) {
	echo "<span class=text>".$lang['nothing_found']."</span><br><br><a href=\"javascript:history.back()\">".$lang['back']."</a>";
} else {
    include (PMDROOT . "/includes/template_listing_results.php");
}

if ( $results_amount > $config['count_search'] ) {
    $keywordencoded = urlencode($_GET['keyword']);
    $catencoded = urlencode($_GET['category']);
    $locencoded = urlencode($_GET['location']);
    $zipcoded = urlencode($_GET['zip']);
    $zip_milescoded = urlencode($_GET['zip_miles']);
    if ($config['mod_rewrite'] == "YES") {
 		echo paginate($results_amount, $config['count_search'], 25, $page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], "search-all.php?keyword=$keywordencoded&location=$locencoded&category=$catencoded&zip=$zipcoded&boolean_type=$boolean_type&zip_miles=$zip_milescoded");
 	}
 	else{
 		echo paginate($results_amount, $config['count_search'], 25, $page, $lang['previous'], $lang['next'], $lang['first'], $lang['last'], "search-all.php?keyword=$keywordencoded&location=$locencoded&category=$catencoded&zip=$zipcoded&boolean_type=$boolean_type&zip_miles=$zip_milescoded");
 	}
	echo "<br><br>";
}
$listing_results = ob_get_contents();
ob_end_clean();



$template_content = & new PMDTemplate(PMDROOT.TEMPLATE_PATH.'search-all.tpl');
if($config['search_display_all'] != 'YES') {
    include (PMDROOT.'/includes/template_searchform.php');
    $template_content->set('searchform',$searchform);
}
$template_content->set('lang',$lang);
$template_content->set('listing_results',$listing_results);

include(PMDROOT.'/includes/template_setup.php');
?>
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 05:09 PM Re: A Stab In The Dark Asking This...
Extreme Talker

Posts: 182
Trades: 0
Whoa Nellie!

Ok, you must be dealing with large app.

It seems like the query logic is in the zipLocator class. I'd have to look at that.
bhgchris is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A Stab In The Dark Asking This...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47736 seconds with 12 queries