I'm trying to create my own blog in CodeIgniter.
One key feature of a blog, is that you can search for posts by using some keywords.
These keywords must be found in the title, content, category and/or keywords.
I'm still working on my database (e.g. extracting category and keywords into seperate tables), but this is what I've got so far
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`content` varchar(10000) NOT NULL,
`date` date NOT NULL,
`keywords` varchar(255) NOT NULL,
`category` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `titel` (`title`),
FULLTEXT KEY `title` (`title`),
FULLTEXT KEY `content` (`content`),
FULLTEXT KEY `keywords` (`keywords`),
FULLTEXT KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
I'm not sure about the content column, probably should use text
instead of varchar(10000)
In my table, I have 2 posts
ID | TITLE | CONTENT | DATA | KEYWORDS | CATEGORY
---+------------------------------+------------------+------------+----------------+----------------------
1 | Welcome to my website | A few paragraphs | 2014-02-09 | Welcome | Site
2 | All Windows Keyboard layouts | A few paragraphs | 2014-03-11 | A few keywords | Windows Deployment
My query is as follow, I tried to keep is as simple as possible for now
SELECT *
FROM `posts`
WHERE MATCH(`title`) AGAINST('Welcome');
I can't seem to figure out why phpMyAdmin doesn't return a thing.
I also tried a more complex query to see if it returns anything, without any luck
SELECT *, MATCH(`title`) AGAINST('Welcome') AS Relevance
FROM `posts`
WHERE MATCH(`title`) AGAINST('Welcome')
ORDER BY `Relevance` DESC
If I understand correctly, MATCH x AGAINST y
can be with multiple keywords.
That's what I'm looking for. I want to be able to add a couple of keywords to the query and find the posts that score highest relevance in title, content, keywords and category