Welcome Guest, Not a member yet? Register   Sign In
Search form/engine

[eluser]someone Smile[/eluser]

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:
$this->db->select('title, content, date, url')->like(array('title' => $keyword, 'content' => $keyword))->order_by('id_article', 'desc')->get('news');

Thanks! :-)

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

[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! :-)

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.

[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! :-)

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.

Theme © iAndrew 2016 - Forum software by © MyBB