CodeIgniter Forums
Search form/engine - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Search form/engine (/thread-50738.html)



Search form/engine - El Forum - 04-06-2012

[eluser]someone Smile[/eluser]
Hello!

I'm working on a news's search form/engine and I have some problem with LIKE (I already read about MATCH and AGAINST, but that don't help me, because I have different table type). If I search for 'word' and if the title of article is 'This is text of word', the title will be find. But if I search for 'This is text of word' or 'This is text of' or 'This is text', there is no results.

This is query which I use:
Code:
$this->db->select('title, content, date, url')->like(array('title' => $keyword, 'content' => $keyword))->order_by('id_article', 'desc')->get('news');

Thanks! :-)


Search form/engine - El Forum - 04-06-2012

[eluser]Denzel[/eluser]
The query is using AND to combine the search for both LIKE statements. Essentially you are looking for a 'title' that contains "This is text of" AND 'content' that contains "This is text of". Is this what you intended?

Maybe you were looking for or_like (scroll down). Using something similar to:
Code:
->or_like(array('title' => $keyword, 'content' => $keyword))
will look for articles having a 'title' that contains "This is text of" OR 'content' that contains "This is text of".

Feel free to clarify your problem with more of an explanation if that wasn't what you were looking for.


Search form/engine - El Forum - 04-07-2012

[eluser]someone Smile[/eluser]
I change like to or_like now, and there are more results if I search for only one word -> 'This', 'is', 'text', 'of', 'word'.

If I search for more words like 'This is' or something else, there are no results. Do I have to explode words and then search for each word?

Thanks! :-)


Search form/engine - El Forum - 04-07-2012

[eluser]Denzel[/eluser]
I don't know what you need to do because it depends on what you want to accomplish. You have yet to make clear what exactly you're expecting.

If you don't understand queries, grab a book on SQL before tackling this. If you don't understand the CodeIgniter API, specify what you are trying to accomplish and the results you expect with a small example data set and sample queries.


Search form/engine - El Forum - 04-07-2012

[eluser]someone Smile[/eluser]
I have a form with search field, which search in database for some news/articles. When user enter some query, search form should find some news/articles from database. But in my case if user enter only one word for query there are results and if more words serperated with space, there are not results. I would like to search news/articles in case of one word or more of them serperated with space.

I have read the best way for searching in database is MATCH and AGAINST, but there is FULLTEXT index for field in table required. Tables in my database are InnoDB type and not other, where I could use FULLTEXT, but I would like to use InnoDB anyway.

What's the best way to do search form/engine with more words functionally?

Thanks! :-)


Search form/engine - El Forum - 04-07-2012

[eluser]Denzel[/eluser]
The simplest way would be to explode on the space and then pass that array of words in to like, if that is in fact the functionality you are after.