Jump to content

PHP full text search


littlea5h

Recommended Posts

Hey guys, i am trying to implement this piece of code around a full text search but i havent worked with them before. I want that the user doesnt have to enter all of the keyword entered, so they can type half the keyword and it will still display the result. This is what i have so far!

public function fetchAllByDescription($description){
        $db = Zend_Db_Table::getDefaultAdapter();
        $statement_front = "SELECT * FROM p2_parts p INNER JOIN p2_parts_category c ON p.partNumber = c.partNumber WHERE";
        $sql = $statement_front." p.description LIKE '%{$description}%' OR c.category LIKE '%{$description}%' LIMIT 200";
        $select = $db->query($sql);
        $results = $select->fetchAll();
        if (0 == count($results)) {
            return;
        }
        $products = array();
        foreach($results as $r) {
            if(isset($r['ID'])){
            $products[] = $this->find($r['ID']);
            }
        }
        return $products;
    }
 

 

Any help would be appreciated. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/275270-php-full-text-search/
Share on other sites

Seeing as FULLTEXT searches is a MySQL question, and nothing to do with PHP, I've moved this to the correct section.

 

Also, what you have there is not a fulltext search. It's a regular "partial match" search. So before anything, I would recommend you to actually read up on fulltext searches in MySQL.

That said, what is your question? I don't see one in your post, and I'm afraid I cannot read your mind. So please remember to give an accurate and full description of your issue, preferably complete with examples of what you want (and what you're getting). That way we will, hopefully, have all of the information we need to help you, straight away, instead of having to waste a lot of time asking you for every single detail (or guess at them).

Thank you.

I have tried to alter the code to a fulltext search. As i stated previously, the code i posted earlier was not fulltext as i have not come across the method. I changed the code to this however it still doesnt seem to be working. It just displays the message that shows up to the user that they can not find the keyword. 

 

 

 

$statement_front = "SELECT * FROM p2_parts p INNER JOIN p2_parts_category c ON p.partNumber = c.partNumber WHERE";
        $sql = $statement_front." MATCH (p.manufacturer,p.description) AGAINST ('+{$description} IN BOOLEAN MODE') AND p.description LIKE '%{$description}%' OR c.category LIKE '%{$description}%' LIMIT 200";
        $select = $db->query($sql);
        $results = $select->fetchAll();
 

Instead of the user wanting to type in the full keyword, i would like it so that they would only enter part of a keyword so it shows something similar. E.g 'key' would display 'keyboard' or 'board' would display 'motherboard, 'keyboard' etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.