Welcome Guest, Not a member yet? Register   Sign In
FULLTEXT search codeigniter
#1

[eluser]Unknown[/eluser]
Hi guys, I am trying to create a full text search for my site but am having little luck.

I have created a FULLTEXT index in my MySQL db (storage type MyISAM). The FULLTEXT index contains the following fields 'title,intro,content'.

I have then proceeded to create my MVC for the search. Code is as follows:

View

Code:
<?php echo form_open('search'); ?>
<?php echo form_label('Search:', 'search-box'); ?>
<?php echo form_input('searchquery', 'searchquery'); ?>
<?php echo form_submit('search', 'Search'); ?>
<?php echo form_close(); ?>

//echo search results
   <?php foreach ($searchcontent as $s): ?>
                <?php echo $s['title']; ?>
                <?php echo $s['intro']; ?>
                <?php echo $s['content']; ?>    
            <?php endforeach; ?>

Controller

Code:
class Search extends CI_Controller {
    
    public function index()
    {

//Content model is autoloaded    
  
         if ($this->input->post('searchquery'))
        {
        //Get data from content where page = $page
        $searchquery =  $this->input->post('searchquery');
        $viewdata['searchcontent'] = $this->Content_model->search($searchquery);
        $this->load->view('search',$viewdata);
        }
        else ($this->load->view('search'));    
    
    }
    
}


Model

Code:
function search($searchquery)
    {
        // Execute our SQL statement and return the result
        $sql = "SELECT title,intro,content
                    FROM content
                    WHERE MATCH (content) AGAINST (?) > 0";
        $query = $this->db->query($sql, array($searchquery, $searchquery));
        
        foreach ($query->result() as $row) {
        $searchquery[] = array(
            'title' => $row->title,
            'intro' => $row->intro,
            'content' => $row->content
        );
    }

    return $searchquery;
        
    }


I can't seem to retrieve any search results with the above, is there something wrong with the code, is there any documentation on performing the above?


Messages In This Thread
FULLTEXT search codeigniter - by El Forum - 10-29-2011, 05:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB