Welcome Guest, Not a member yet? Register   Sign In
serch engine in my own webiste using code igniter
#1

[eluser]Unknown[/eluser]
I have a site made using code igniter and now i have to give a function of seach in my website that serches through keyword given by user through input text field.
Is there any concept of how i make this possible?
I have read about php search script Sphider.I like it but don't know how to integrate it within my website.So can anyone help me.
Thanks
#2

[eluser]srpurdy[/eluser]
This just depends on what you want to do with it, and how much options you want.

For example really basic example:

Code needed for controller method.
Code:
$this->load->model('search_model');
$data['do_search'] = $this->search_model->do_search($this->input->post('search'));

model method do_search
Code:
function do_search($terms)
{
$terms_array = explode(' ', $terms);

$this->db->like('text', $terms);
foreach($terms_array as $key)
  {
  $this->db->or_like('text', $key);
  }
$this->db->select('text,name');
$this->db->from('pages');
$search = $this->db->get();
return $search;
}

View - just foreach the result from above.
Code:
<?php foreach($do_search->result() as $ds):?>
<?php endforeach;?>

Of course you might want to put some limitations like a min amount of characters at least. This is about as simple as it gets. You can pretty easily build on it though. Smile

And also which fields in your db you actually want to search through. Smile




Theme © iAndrew 2016 - Forum software by © MyBB