Wednesday, 26 March 2014

Full text Search



Full-Text Searches PHP - Mysql

Lekhulal 

lekhulal@gmail.com

---------------------------------------------------------------------------------------------

--
--
-Create a table called articles
-That table type must support FULLTEXT indexes.
-Set of one or more columns included in a FULLTEXT index.
--
--

CREATE TABLE articles
(
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
);


--
--
Insert values into table called articles
--
--

INSERT INTO articles (title,body)
VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');


--
--
-Write query for full text search.
-The search string is given as the argument to AGAINST().
-For each row in the table, MATCH() returns a relevance value.
-The search is performed in case-insensitive.
--
--

SELECT * FROM articles
WHERE MATCH (title,body) AGAINST ('database');


--
--
-The number of unique words in that row.
--
--

SELECT
COUNT(IF(MATCH (title,body) AGAINST ('database'), 1, NULL))
AS count
FROM articles;


--------------------------------------- Thank You -------------------------------------

No comments:

Post a Comment