Database Articles

  Home arrow Database Articles arrow Page 3 - Full Text Searches and Strings
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Full Text Searches and Strings - Another Solution


    (Page 3 of 4 )

    Another way to require multiple words is with a Boolean mode search. To do this, precede each word in the search string by a + character and add IN BOOLEAN MODE after the string:

      mysql> SELECT COUNT(*) FROM kjv
         
    -> WHERE MATCH(vtext) AGAINST('+David +Goliath' IN BOOLEAN MODE)
      +----------+
      | COUNT(*) |
      +----------+
      |        2 |
      +----------+

    Boolean mode searches also allow you to exclude words. Just precede any disallowed word by a -character. The following queries select kjv rows containing the name David but not Goliath, or vice versa:

      mysql> SELECT COUNT(*) FROM kjv
         -> WHERE MATCH(vtext) AGAINST('+David -Goliath' IN BOOLEAN MODE)
      +----------+
      | COUNT(*) |
      +----------+
      |      928 |
      +----------+
      mysql> SELECT COUNT(*) FROM kjv
         
    -> WHERE MATCH(vtext) AGAINST('-David +Goliath' IN BOOLEAN MODE)
      +----------+
      | COUNT(*) |
      +----------+
      |        4 |
      +----------+

    Another useful special character in Boolean searches is *; when appended to a search word, it acts as a wildcard operator. The following statement finds rows containing not only whirl, but also words such as whirls, whirleth, and whirlwind:

      mysql> SELECT COUNT(*) FROM kjv
         -> WHERE MATCH(vtext) AGAINST('whirl*' IN BOOLEAN MODE);
      +----------+
      | COUNT(*) |
      +----------+
      |       28 |
      +----------+

    For a complete list of Boolean FULLTEXT operators, see the MySQL Reference Manual.

    More Database Articles Articles
    More By O'Reilly Media

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap