Database Articles
  Home arrow Database Articles arrow Page 4 - Full Text Searches and Strings
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE ARTICLES

Full Text Searches and Strings
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-09-27

    Table of Contents:
  • Full Text Searches and Strings
  • 5.17 Requiring or Excluding FULLTEXT Search Words
  • Another Solution
  • 5.18 Performing Phrase Searches with a FULLTEXT Index

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Full Text Searches and Strings - 5.18 Performing Phrase Searches with a FULLTEXT Index


    (Page 4 of 4 )

    Problem

    You want to perform a FULLTEXT search for a phrase; that is, for words that occur adjacent to each other and in a specific order.

    Solution

    Use the FULLTEXT phrase-search capability.

    Discussion

    To find rows that contain a particular phrase, you can’t use a simple FULLTEXT search:

      mysql> SELECT COUNT(*) FROM kjv
         
    -> WHERE MATCH(vtext) AGAINST('still small voice');
      +----------+
      | COUNT(*) |
      +----------+
      |      548 |
      +----------+

    The query returns a result, but it’s not the result you’re looking for. A FULLTEXT search computes a relevance ranking based on the presence of each word individually, no matter where it occurs within the vtext column, and the ranking will be nonzero as long as any of the words are present. Consequently, this kind of statement tends to find too many rows.

    Performing Phrase Searches with a FULLTEXT Index

    FULLTEXT searching supports phrase searching in Boolean mode. To use it, place the phrase in double quotes within the search string:

      mysql> SELECT COUNT(*) FROM kjv
         
    -> WHERE MATCH(vtext) AGAINST('"still small voice"' IN BOOLEAN MODE);
      +----------+
      | COUNT(*) |
      +----------+
      |        1 |
      +----------+

    A phrase match succeeds if a column contains the same words as in the phrase, in the order specified.


    * The use of COUNT( ) to produce multiple counts from the same set of values is described in Recipe 8.1.

    † If you change ft_min_word_len, you must also use REPAIR TABLE to rebuild the indexes for all other tables thathave FULLTEXT indexes.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "MySQL Cookbook, Second Edition," published...
     

    Buy this book now. This article is excerpted from chapter five of the MySQL Cookbook, Second Edition, written by Paul DuBois (O'Reilly; ISBN: 059652708X). Check it out today at your favorite bookstore. Buy this book now.

    DATABASE ARTICLES ARTICLES

    - More on Query Optimization for Oracle Databa...
    - Query Optimization in Oracle
    - Clusters and Other Data Structures for Oracle
    - Using Indexes with an Oracle Database
    - The Basics of Data Structures in Oracle
    - Oracle Data Structures
    - Best Practices for PL/SQL Variables
    - What`s Code Without Variables?
    - Clauses, Sorting, and SQL Queries
    - The From Clause and SQL Queries
    - Query Primer
    - Full Text Searches and Strings
    - Searching with Strings
    - Pattern Matching with Strings
    - Working with Cases of Strings






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway