Help - Search - Members - Calendar
Full Version: site search not showing correct results
HTMLHelp Forums > Programming > Server-side Scripting
TFSL
ok all hi,

sorry if this is in the wrong place,

ok iv got a bit of a problem what is bugging me really bad, you see im using a script freeglobes, now the script is fine its self, and i like it but the support forum is awful, hence why im in here

ok my problem is i have a niche website that deal with fireworks, i have over 369 websites posted on there, but when i type in the search field the name of the website is doesn't show me the correct results,

EG, if i type in daves fireworks i get over 108 results that or not the results i asked for,

but if i just type in dave then i get the website up first choice,

here is the source code for the search i have on my site:

CODE
<?php

if(isset($_REQUEST["seek"]) and !empty($_REQUEST["seek"]) and strlen($_REQUEST["seek"]) >= $CONFIG['search_minlength'])
{
    $seek = $_REQUEST["seek"];
}
else if(!isset($_REQUEST['id']) || empty($_REQUEST['id']))
{
    $seek = "";
}

if (!empty($seek))
{
    if(isUTF8($seek)) {
        $seek = utf8_decode($seek);
    }
    $seek = strip_tags($seek);
    
    $km =& get_manager("keyword");
    $lm =& get_manager("link");
    $myts =& MyTextSanitizer::getInstance();
    $re = MyRewriteEngine::getInstance();
    
    $my_url = 'index.php?do=recherche&seek='.$seek;
    $start = isset($_GET['start']) ? $_GET['start'] : 0;
    $limit = 10;
    
    $recherche = strtolower($seek);

    $mots = str_replace('+', ' ', trim($recherche));
    $mots = str_replace('\'', ' ', $mots);
    $mots = str_replace('%', ' ', $mots);
    $mots = str_replace(',', ' ', $mots);
    $mots = str_replace(':', ' ', $mots);

    $tab = explode(' ' , $mots);
    $nb = count($tab);
    
    $criteriacompo = new CriteriaCompo(new Criteria('id',0,'='),'OR');

    for($i = 0; $i < $nb; $i++)
    {
        if(strlen($tab[$i]) >= $CONFIG['search_minlength'])
        {
            $criteriacompo->add(new Criteria('name',"%".$tab[$i]."%",'LIKE'),'OR');
            $criteriacompo->add(new Criteria('description',"%".$tab[$i]."%",'LIKE'),'OR');
        }
    }

    $criteriacompo2 = new CriteriaCompo($criteriacompo,'AND');
    $criteriacompo2->add(new Criteria('state',4,'='),'AND');
    
    $total_items = $lm->getCount($criteriacompo2);
    $smarty->assign('total_results',$total_items);
    
    $criteriacompo2->setOrder('DESC');
    $criteriacompo2->setSort('hits');
    $criteriacompo2->setLimit($limit);
    $criteriacompo2->setStart($start);

    // Cols to be selected
    $cols = array('id', 'name', 'url', 'description', 'pr', 'category', 'image', 'hits','vote');
    // retrieving objects
    $links =& $lm->getObjects($criteriacompo2,$cols);
    
    $total_keywords = $km->getCount();
    
    $hasresults = count($links) == 0 ? 0 : 1;
    
    if(count($links) > 0)
    {
        affichage_liens($links, $CONFIG['url_rewriting'], 1);
    }
    else
    {
        // No results
    }
    
    $smarty->assign("resultsfor",$lang['resultsfor']);
    $smarty->assign('searched_expr',$recherche);
    
    $pagenav = new PageNav($total_items, $limit, $start, $my_url);
    
    $smarty->assign('pagenav',$pagenav->renderNavNormal());
    
    if($total_keywords <= $CONFIG['max_keywords'] || $CONFIG['max_keywords'] == 0)
    {
        $criteria = new Criteria('word',$recherche,'=');
        $criteria->setLimit(1);
        $cols = array('occurence');
        $keywords =& $km->getObjects($criteria,$cols);
        
        if(count($keywords) > 0 && !isset($_COOKIE[$recherche]))
        {
            $attributes = array('occurence' => $keywords[0]->getVar('occurence')+1, 'date' => date("Y-m-d"), 'hasresults' => $hasresults);
            $km->update($criteria, $attributes);
        }
        else if(count($keywords) == 0)
        {
            $keyword = $km->create(true);
            $keyword->setVars(array('id' => '', 'word' => $recherche, 'occurence' => 1, 'date' => date("Y-m-d"), 'hasresults' => $hasresults));
            $km->insert($keyword);
        }
        
        // Count only one search per word per day per user
        @ setcookie($recherche,'1', time()+3600*24);
    }
}
else if (!isset($_POST["seek"]))
{
    $directory =& MyDirectory::getInstance();
    $directory->error301('./');
}
else
{
    $smarty->assign("message",$lang['search_moreprecise']);
}
?>


i have spent a best part of 2 weeks doing this and there's no way on sorting it,

if any one can give me some idea on how to sort this, i will repay you many times with thanks wink.gif

TFSL


Darin McGrew
This is PHP, so I'm moving it to the Server-side Scripting forum.
Brian Chandler
QUOTE
ok iv got a bit of a problem what is bugging me really bad, you see im using a script freeglobes, now the script is fine its self, and i like it but the support forum is awful, hence why im in here


But I'm afraid *no-one* wants to try to debug an uncommented script from someone else who gives no support. It would probably be easier to start again and write a new program.

Your explanation isn't particularly clear, either. What does: "i have over 369 websites posted on there" mean? Where is "there"? Do you mean "over 369 pages"? (Wouldn't "over 369" be 370?

The page you have posted is only part of the program -- it's using something called Xoops (about which I know nothing), so you need a much more specific expert to sort it out.

Alternatively: (a) give up (b) notice that perhaps it only does "OR" searches, so of course "Dave fireworks" returns all the pages.... ?
TFSL
QUOTE(Brian Chandler @ May 28 2009, 03:14 AM) *

QUOTE
ok iv got a bit of a problem what is bugging me really bad, you see im using a script freeglobes, now the script is fine its self, and i like it but the support forum is awful, hence why im in here


But I'm afraid *no-one* wants to try to debug an uncommented script from someone else who gives no support. It would probably be easier to start again and write a new program.

Your explanation isn't particularly clear, either. What does: "i have over 369 websites posted on there" mean? Where is "there"? Do you mean "over 369 pages"? (Wouldn't "over 369" be 370?

The page you have posted is only part of the program -- it's using something called Xoops (about which I know nothing), so you need a much more specific expert to sort it out.

Alternatively: (a) give up (b) notice that perhaps it only does "OR" searches, so of course "Dave fireworks" returns all the pages.... ?


ok let me first say sorry if i have offended you in any way ...

and yes my description of my problem isn't clear so let me clarify again,

the support is there on the forums but no one will answer in English, its a pain in the... and this is why im here to see if any one else can solve the it and can give me a direct answer in English.

problem is, when ever i search a name i.e "daves fireworks" the results don't come out to what im searching

but if i just search "dave" i get the correct results

this is the same problem im having with all websites listed on my websites

so in short "i am getting the correct result on 1 keyword to if i search with 2 keywords i don't get the right results"

hope you under stand that more clearly

the search form im using:

CODE
<form method="post" action="<{$search_form_action}>" class="style1">
    <input name="seek" type="text" style="width: 350px" value="Search Here....." /><input name="Submit1" type="submit" value="submit" /></form>


and here is the script that works the search, the file name is called recherche.php
CODE
<?php

if(isset($_REQUEST["seek"]) and !empty($_REQUEST["seek"]) and strlen($_REQUEST["seek"]) >= $CONFIG['search_minlength'])
{
    $seek = $_REQUEST["seek"];
}
else if(!isset($_REQUEST['id']) || empty($_REQUEST['id']))
{
    $seek = "";
}

if (!empty($seek))
{
    if(isUTF8($seek)) {
        $seek = utf8_decode($seek);
    }
    $seek = strip_tags($seek);
    
    $km =& get_manager("keyword");
    $lm =& get_manager("link");
    $myts =& MyTextSanitizer::getInstance();
    $re = MyRewriteEngine::getInstance();
    
    $my_url = 'index.php?do=recherche&seek='.$seek;
    $start = isset($_GET['start']) ? $_GET['start'] : 0;
    $limit = 10;
    
    $recherche = strtolower($seek);

    $mots = str_replace('+', ' ', trim($recherche));
    $mots = str_replace('\'', ' ', $mots);
    $mots = str_replace('%', ' ', $mots);
    $mots = str_replace(',', ' ', $mots);
    $mots = str_replace(':', ' ', $mots);

    $tab = explode(' ' , $mots);
    $nb = count($tab);
    
    $criteriacompo = new CriteriaCompo(new Criteria('id',0,'='),'OR');

    for($i = 0; $i < $nb; $i++)
    {
        if(strlen($tab[$i]) >= $CONFIG['search_minlength'])
        {
            $criteriacompo->add(new Criteria('name',"%".$tab[$i]."%",'LIKE'),'OR');
            $criteriacompo->add(new Criteria('description',"%".$tab[$i]."%",'LIKE'),'OR');
        }
    }

    $criteriacompo2 = new CriteriaCompo($criteriacompo,'AND');
    $criteriacompo2->add(new Criteria('state',4,'='),'AND');
    
    $total_items = $lm->getCount($criteriacompo2);
    $smarty->assign('total_results',$total_items);
    
    $criteriacompo2->setOrder('DESC');
    $criteriacompo2->setSort('hits');
    $criteriacompo2->setLimit($limit);
    $criteriacompo2->setStart($start);

    // Cols to be selected
    $cols = array('id', 'name', 'url', 'description', 'pr', 'category', 'image', 'hits','vote');
    // retrieving objects
    $links =& $lm->getObjects($criteriacompo2,$cols);
    
    $total_keywords = $km->getCount();
    
    $hasresults = count($links) == 0 ? 0 : 1;
    
    if(count($links) > 0)
    {
        affichage_liens($links, $CONFIG['url_rewriting'], 1);
    }
    else
    {
        // No results
    }
    
    $smarty->assign("resultsfor",$lang['resultsfor']);
    $smarty->assign('searched_expr',$recherche);
    
    $pagenav = new PageNav($total_items, $limit, $start, $my_url);
    
    $smarty->assign('pagenav',$pagenav->renderNavNormal());
    
    if($total_keywords <= $CONFIG['max_keywords'] || $CONFIG['max_keywords'] == 0)
    {
        $criteria = new Criteria('word',$recherche,'=');
        $criteria->setLimit(1);
        $cols = array('occurence');
        $keywords =& $km->getObjects($criteria,$cols);
        
        if(count($keywords) > 0 && !isset($_COOKIE[$recherche]))
        {
            $attributes = array('occurence' => $keywords[0]->getVar('occurence')+1, 'date' => date("Y-m-d"), 'hasresults' => $hasresults);
            $km->update($criteria, $attributes);
        }
        else if(count($keywords) == 0)
        {
            $keyword = $km->create(true);
            $keyword->setVars(array('id' => '', 'word' => $recherche, 'occurence' => 1, 'date' => date("Y-m-d"), 'hasresults' => $hasresults));
            $km->insert($keyword);
        }
        
        // Count only one search per word per day per user
        @ setcookie($recherche,'1', time()+3600*24);
    }
}
else if (!isset($_POST["seek"]))
{
    $directory =& MyDirectory::getInstance();
    $directory->error301('./');
}
else
{
    $smarty->assign("message",$lang['search_moreprecise']);
}
?>


now if you need to see a visual proof pm me for the website
Brian Chandler
QUOTE
ok let me first say sorry if i have offended you in any way ...


Not offended at all! Slightly frustrated, because the same sort of question keeps appearing. Is there a FAQ somewhere explaining what "debugging" means? (Darin??)

The point is that it's not reasonable to attempt to find the problem by just staring at the program. You have to pick it to bits: find exactly what database query is generated by a search for more than one word. Typically this sort of question is best answered by the program author or support team. If they won't, I seriously suggest you look for a new search program.

Of course, if they will give you an answer in French, you could always post the answer for someone to help with...
Darin McGrew
Well, there's the Wikipedia article...
TFSL
ok thanks guys
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.