Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-30-2009, 11:22 AM   PM User | #1
crazyeights
New Coder

 
Join Date: Oct 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
crazyeights has a little shameless behaviour in the past
Smile Need help with relevant searching.

The script below only allows me to search if the input fields match EXACTLY. However, I need the script to basically work like this:

It needs to be able to take all the fields I populate and give me the "BEST MATCH" as the top result. So say I select Blue Eyes, Brown Hair, Asian, and US as country. I need it to show me the exact matches IF ANY on top, then as you go down the line, it shows people who semi-match my query, some that are only blue eyes, brown hair, and us, and as the results go lower and lower, the fields get narrower, and narrower.

I don't know the term for this, but the code for my script's search library is below. I don't expect the script mod I need to be solved here, but I just need the term I'm referring to, and a point in the right direction. I'm getting bids to do this for 20-60 bucks on freelance sites, so that makes me assume this is an easy fix, but have no clue on how to approach it. I'm still new to PHP, about 3 months now.

I've attached the script

lib.search.php.zip
crazyeights is offline   Reply With Quote
Old 10-30-2009, 01:40 PM   PM User | #2
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
1,500+ lines of code in there. I'm kindly going to decline attempting to learn all that code to provide a solution ... but I would recommend looking into a full text search:
http://dev.mysql.com/doc/refman/5.0/...xt-search.html
http://devzone.zend.com/article/1304

Then you'd form your search query using the following syntax:
Code:
SELECT *, MATCH( `field1`, `field2`, `...` ) AGAINST( 'Your search terms' ) AS `score`
FROM `table_name`
WHERE MATCH( `field1`, `field2`, `...` ) AGAINST( 'Your search terms' )
ORDER BY `score` DESC
__________________
ZCE
kbluhm is offline   Reply With Quote
Old 10-30-2009, 01:55 PM   PM User | #3
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
ill join kbluhm with that lol
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Old 10-30-2009, 11:31 PM   PM User | #4
crazyeights
New Coder

 
Join Date: Oct 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
crazyeights has a little shameless behaviour in the past
Ya, I figured it was a bit long, but I found the QUERIES of the script which in my guess does all the searching. What can I change to make it match by percentage.

PHP Code:

                        
if ($profile_field['field_label'] == "uszip")
                        {
                            if (isset(
$_POST['uszip']))
                                
$uszip $DB->add_slashes(trim($_POST['uszip']));
                            elseif (isset(
$_GET['uszip']))
                                
$uszip $DB->add_slashes(trim($_GET['uszip']));
                            if (isset(
$_POST['dist']) && $_POST['dist'])
                                
$dist $DB->add_slashes(trim($_POST['dist']));
                            elseif (isset(
$_GET['dist']) && $_GET['dist'])
                                
$dist $DB->add_slashes(trim($_GET['dist']));
                            
$zipfield = isset($uszip) && $uszip "d.data_" $field_label null;
                        }
                        elseif (
$profile_field['field_type'] == "birthday")
                        {
                            if (isset(
$_POST[$profile_field['field_label'].'_from'])  &&  $_POST[$profile_field['field_label'].'_from'])
                                
$search_fields[] = "d.data_" $field_label "<=" . (date("Y") - intval($_POST[$profile_field['field_label'].'_from'])) . date("m") . date("d");
                            elseif (isset(
$_GET['age_from'])  &&  $_GET['age_from'])
                                
$search_fields[] = "d.data_" $field_label "<=" . (date("Y") - intval($_GET[$profile_field['field_label'].'_from'])) . date("m") . date("d");

                            if (isset(
$_POST[$profile_field['field_label'].'_to'])  &&  $_POST[$profile_field['field_label'].'_to'])
                                
$search_fields[] = "d.data_" $field_label ">=" . (date("Y") - intval($_POST[$profile_field['field_label'].'_to']) - 1) . date("m") . date("d");
                            elseif (isset(
$_GET[$profile_field['field_label'].'_to'])  &&  $_GET[$profile_field['field_label'].'_to'])
                                
$search_fields[] = "d.data_" $field_label ">=" . (date("Y") - intval($_GET[$profile_field['field_label'].'_to']) - 1) . date("m") . date("d");
                        }
                        elseif (
$profile_field['field_type'] == "checkbox")
                        {
                            
$checkboxes = array();
                            if (isset(
$_POST[$profile_field['field_label']])) {
                                if ( 
is_array($_POST[$profile_field['field_label']]) ) {
                                    
$checkboxes = ( isset($_POST[$profile_field['field_label']]) ) ? $_POST[$profile_field['field_label']] : array();
                                }
                                else {
                                    
$checkboxes = array($_POST[$profile_field['field_label']]);
                                }
                            }
                            elseif (isset(
$_GET[$profile_field['field_label']])) {
                                if ( 
is_array($_GET[$profile_field['field_label']]) ) {
                                    
$checkboxes = ( isset($_GET[$profile_field['field_label']]) ) ? $_GET[$profile_field['field_label']] : array();
                                }
                                else {
                                    
$checkboxes = array($_GET[$profile_field['field_label']]);
                                }
                            }
                            foreach (
$checkboxes as $item_id) {
                                if ( 
is_numeric($item_id) ) {
                                    
$search_items[] = $item_id;
                                }
                            }
                        }
                        elseif (
$profile_field['field_type'] == "combo" || $profile_field['field_type'] == "radio")
                        {
                            
$values = array();
                            if (isset(
$_POST[$profile_field['field_label']])) {
                                
$values $_POST[$profile_field['field_label']];
                            }
                            elseif (isset(
$_GET[$profile_field['field_label']])) {
                                
$values $_GET[$profile_field['field_label']];
                            }
                            if ( 
is_array($values) && $values ) {
                                
$search_values = array();
                                foreach ( 
$values as $value ) {
                                    
$search_values[] = $DB->add_slashes(trim($value));
                                }
                                if ( 
$search_values ) {
                                    if ( 
count($search_values) > ) {
                                        
$search_fields[] = "d.data_".$field_label." IN (".implode(","$search_values).")";
                                    }
                                    else {
                                        
$search_fields[] = "d.data_" $field_label "=" current($search_values);
                                    }
                                }
                            }
                            elseif (
$values) {
                                
$search_fields[] = "d.data_" $field_label "=" $DB->add_slashes(trim($values));
                            }
                        }
                        else
                        {
                            if (isset(
$_POST[$profile_field['field_label']]) && trim($_POST[$profile_field['field_label']]))
                                
$search_fields[] = "d.data_" $field_label " LIKE '%" $DB->add_slashes(trim($_POST[$profile_field['field_label']])) . "%'";
                            elseif (isset(
$_GET[$profile_field['field_label']]) && trim($_GET[$profile_field['field_label']]))
                                
$search_fields[] = "d.data_" $field_label " LIKE '%" $DB->add_slashes(trim($_GET[$profile_field['field_label']])) . "%'";
                        }
                    }

                    
$j++;
                }
            } 
crazyeights is offline   Reply With Quote
Old 11-01-2009, 08:40 AM   PM User | #5
crazyeights
New Coder

 
Join Date: Oct 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
crazyeights has a little shameless behaviour in the past
BUMP, any direction I can take. I realize the code above, but that is for full-text only.
crazyeights is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 07:33 AM.


Advertisement
Log in to turn off these ads.