Doing Relevance Ranked Full-Text Searches In MySQL

I’m going out on a limb to say MySQL’s full-text indexing and searching features are underused. They appeared in MySQL 3.23.23 (most people are using 4.x, and 5 is in development), but it’s been news to most of the people I know.

Here’s the deal, the MATCH() function can search a full-text index for a string of text (one or more words) and return relevance-ranked results. It’s at the core of the list of related links at the bottom of every post here.

For that query, I put all the tag names into a single variable that might look like this:

$keywords = “mysql database php select full-text search full-text searching docs documentationâ€

Then I do a select that looks something like this:

SELECT * FROM wp_posts WHERE MATCH(post_title,post_content) AGAINST(’$keywords’);

The docs give a lot more detail, including how to do boolean searches.

tags: , , , , , , , , , , , , , , , , , , , , , ,

8 Comments

  1. Pingback by Plesk Bites « MaisonBisson.com on January 26, 2006 7:59 pm

    [...] Why? Because MySQL 3.x doesn’t support query caching, boolean full-text searching, or complex subqueries. [...]

  2. Pingback by Epsilon-Delta: Mathematics and Computer Programming » Dissecting MySQL Fulltext Indexing on February 8, 2006 8:53 pm

    [...] MySQL provides two types of fulltext searches - boolean and natural language. I’m going to focus on the natural language search because it is more mathematically intense. The underlying concept behind the method used in MySQL is that each term in each document is assigned a specific weight which is used to decide a query’s “distance” or “score” with respect to that document. The weights are assigned such that the weight is increased if the term occurs frequently in the document, but decreased in the term occurs frequently among all documents. For a description of how the weights are computed, check out the MySQL documentation. For the curious reader, this article also explains the computation of word-document weights. There are also a slew of articles on using fulltext search in practice. [...]

  3. Pingback by Pulni´s private News » Volltextsuche on February 14, 2006 12:33 pm

    [...] MySQL provides two types of fulltext searches - boolean and natural language. I’m going to focus on the natural language search because it is more mathematically intense. The underlying concept behind the method used in MySQL is that each term in each document is assigned a specific weight which is used to decide a query’s “distance†or “score†with respect to that document. The weights are assigned such that the weight is increased if the term occurs frequently in the document, but decreased in the term occurs frequently among all documents. For a description of how the weights are computed, check out the MySQL documentation. For the curious reader, this article also explains the computation of word-document weights. There are also a slew of articles on using fulltext search in practice. [...]

  4. Pingback by Is Sun’s T2000 Up To It? « MaisonBisson.com on February 26, 2006 8:33 pm

    [...] And I’m fully confident that when I put our entire catalog into WPopac, all 330,000 bib records (resulting in about 6.2 million atomic records), performance will still be up to the task. And my math suggests everything should be ducky on a relatively budget server up beyond about 1 million bib records), but what happens for libraries that have more than that, say, perhaps 6 to 8 million bib records (again, 110 to 150 million atomic records; again, all full-text indexed in MySQL)? [...]

  5. Comment by mansoor on April 28, 2006 5:27 pm

    salam dostaneh man harkasi keh mikad ba yek pesarehg 29 saleh mogarad va lisanseh mekanik az thran azdevag koneh ageh be tafahoom residim baram emall bezareh

  6. Pingback by Epsilon-Delta » Dissecting MySQL Fulltext Indexing on May 17, 2006 1:25 pm

    [...] MySQL provides two types of fulltext searches - boolean and natural language. I’m going to focus on the natural language search because it is more mathematically intense. The underlying concept behind the method used in MySQL is that each term in each document is assigned a specific weight which is used to decide a query’s “distance†or “score†with respect to that document. The weights are assigned such that the weight is increased if the term occurs frequently in the document, but decreased in the term occurs frequently among all documents. For a description of how the weights are computed, check out the MySQL documentation. For the curious reader, this article also explains the computation of word-document weights. There are also a slew of articles on using fulltext search in practice. [...]

  7. Comment by taz4mfsd on March 8, 2008 6:21 pm

    sexy gierls

  8. Comment by Rohan Shenoy on April 1, 2008 11:11 am

    Thanks Maison, was looking for it. I wanted to sort the results of SELECT query by releveance. But I was stuck with ‘%LIKE%’. You have helped me out.

    Thanks a lot dear!

Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

sexs (18496) - gogle com (6760) - gogle (6726) - sexs com (1074) - world sex com (1043) - googleheart (559) - gogle earth com (409) - mysql search relevance (239) - gogle it (236) - WORLD SEXS.COM (229) - gogle earth (221) - FUL SEX (207) - ful porno (204) - MySQL relevance (190) - mysql fulltext relevance (152) - WWW GOGLE COM (139) - world sexs (138) - mysql relevance search (127) - WWW GOGLE (123) - WWW ARAB 6 COM (122) - www.sexs.com (117) - sexs.com (115) - www.arab 6.com (112) - world sex (106) - world sexs com (103) - WWW GOGLE EARTH COM (101) - Google Earth com (99) - earth gogle com (99) - full sexs (92) - sexs 6 com (89) - goegle (80) - sexs x (78) - goegle com (77) - www.arab sex.com (69) - fulltext relevance (65) - mysql full text relevance (64) - mysql fulltext search relevance (64) - mysql MATCH relevance (58) - www.arab porno.com (58) - mysql full text search (56) - sexs full (56) - mysql like relevance (54) - relevance mysql (53) - mysql fulltext (52) - WWW SEXS COM (49) - word sexs (47) - gogle de (46) - mysql full text search relevance (44) - mysql 5 full text search (41) - www.arab.6.com (41) - mysql fulltext score (40) - sexs word (39) - www world sex com (39) - gogle com in (38) - www.arab full sex.com (38) - mysql Relevance Ranking (37) - goegle earth (37) - www vorld sex com (37) - WWW SEXS (36) - Search sexs (36) - WWW ARAB SEX COM (36) - www.ful porno.com (36) - all (35) - www arab sexs com (35) - www.arab sexs.com (35) - arab sexs (34) - gogle sex (33) - mysql full text score (33) - MySQL Full Text Search score (33) - mysql fulltext ranking (33) - mysql search by relevance (33) - mysql match against relevance (32) - google S com (32) - www.ful sex.com (32) - www.arab.porno.com (31) - goegle earth com (30) - fulltext mysql (29) - sex 4 (29) - mysql Boolean Full Text Searches (29) - sex ful (28) - gogle sex com (28) - mysql fulltext boolean relevance (28) - 2786506456964 (28) - www.vorld sex.com (27) - www.sex full.com (27) - mysql relevance score (26) - mysql fulltext weight (26) - arab sexs.com (26) - WWW GOGLE EARTH (25) - doing sex (25) - arab porno (24) - mysql relevancy search (24) - full text search relevance (23) - gogle com eart (23) - mysql search relevancy (23) - mysql 5 full text (22) - gogle video 666 (22) - php mysql search relevance (22) - GOOGLE sexs (21) - relevance search mysql (21) - world sex de (21) - w w w gogle com (21) - doing sexs (21) - mysql full text relevancy (21) - www sex full com (21) - WWW GOOGLE EARTH COM (20) - earth gogle (20) - http earth gogle com (20) - word sexs com (20) - mysql 4 full text search (20) - mysql like (20) - full text mysql (20) - shemalles (20) - gogle full (20) - www.vorld.sex.com (19) - mysql (19) - fulltext search relevance (19) - azdevag (19) - mysql fulltext relevancy (19) - www sex s com (19) - www.sex.full.com (18) - google sex (18) - arab 6 com (18) - www sex w (18) - ful.porno (17) - relevance (17) - mysql as relevance (17) - mysql ranked search (17) - www.arab.porno (17) - mysql 5 fulltext (16) - people doing sex (16) - 3038451802374 (16) - www gogle sex (16) - www goegle com (16) - sex full.com (16) - www.world sexs.com (15) - mysql boolean relevance (15) - wordpress fulltext search (15) - arab.porno.com (15) - full.sexs (15) - arab6 (14) - mysql full text (14) - fulltext mysql relevance (14) - MySQL Natural Language (14) - www vorld sex (14) - www goegle earth com (14) - www.vorld sex (14) - www.goegle.com (14) - arab 6.com (14) - full porno.com (14) -