Author Topic: multiple keyword search order  (Read 611 times)

0 Members and 1 Guest are viewing this topic.

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
multiple keyword search order
« on: March 01, 2010, 03:35:16 PM »
create table keyword_relevance
( id tinyint not null primary key auto_increment
, Description longtext
);
insert into keyword_relevance (Description) values
 ('Hello world')
,('hello friends from around the world')
,('friends from around the world')
,('hello my friends')
,('the keyword is not present');


Oki so up until now i was retreving my search results by "SELECT description FROM keyword_relevance WHERE description REGEXP '(hello|world)';"

Now i need to order this result based on the occurence of the search keywords , the more different keywords found in one row the higher will "rank" in the search result query . Question is , can it be done from the sql query ? or do i need to work the php bit to search for each keyword in a different query then test they'r id's and ...

Offline mapleleaf

  • Enthusiast
  • Posts: 237
    • View Profile
Re: multiple keyword search order
« Reply #1 on: March 01, 2010, 10:52:51 PM »
If you put a fulltext index on the Description MYSQL will sort by relevance.

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
Re: multiple keyword search order
« Reply #2 on: March 02, 2010, 03:00:15 AM »
oki thanks , i'll try it out when i get to work and i'll let everibody know how it whent

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
Re: multiple keyword search order
« Reply #3 on: March 27, 2010, 08:57:13 AM »
CREATE TABLE `ci_articles` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `content` longtext,
  `date` int(11) default NULL,
  `author` varchar(255) default NULL,
  `cat` int(11) default NULL,
  `is_page` tinyint(4) default NULL,
  `permalink` varchar(255) default NULL,
  `page_desc` varchar(255) default NULL,
  `page_key` varchar(255) default NULL,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `title` (`title`,`page_key`,`page_desc`,`permalink`)
) ENGINE=MyISAM AUTO_INCREMENT=31 DEFAULT CHARSET=utf8


running the query
SELECT * FROM ci_articles WHERE MATCH(title, page_key) AGAINST('sasa')

produces
Error Number: 1191

Can't find FULLTEXT index matching the column list

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: multiple keyword search order
« Reply #4 on: March 27, 2010, 07:53:42 PM »
That's because you don't have a full-text index on just those 2 columns.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
Re: multiple keyword search order
« Reply #5 on: March 27, 2010, 08:00:54 PM »
CREATE TABLE `ci_articles` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `content` longtext,
  `date` int(11) default NULL,
  `author` varchar(255) default NULL,
  `cat` int(11) default NULL,
  `is_page` tinyint(4) default NULL,
  `permalink` varchar(255) default NULL,
  `page_desc` varchar(255) default NULL,
  `page_key` varchar(255) default NULL,
  `search_content` longtext NOT NULL,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `title` (`title`,`page_key`)
) ENGINE=MyISAM AUTO_INCREMENT=31 DEFAULT CHARSET=utf8


running the query
SELECT * FROM ci_articles WHERE MATCH(title, page_key) AGAINST('sasa')

produces
Error Number: 1096

No tables used

SELECT *

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
Re: multiple keyword search order
« Reply #6 on: March 27, 2010, 08:12:52 PM »
yup works now after i restarted mysql , thanks .

Offline poelincaTopic starter

  • Irregular
  • Posts: 14
    • View Profile
Re: multiple keyword search order
« Reply #7 on: March 27, 2010, 08:23:28 PM »
hey , works like a charm , thanks second error was made by my mistake sorry to fill the forum with uninportant stuff