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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.