SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    MN
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Boolean Searches

    How do Web sites do boolean searches?

    For instance, a user could type "apple AND pie" and it would only return results that contain both and pie.

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    MN
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any way I could make the fulltext search in mysql be a default AND search?

  3. #3
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not familiar with advanced search functionality built into databases, but I can tell you how to handle your AND/OR matching. In your program, you will need to split your keywords by AND/OR, then piece together your search clause accordingly.

    For instance, if the search term is "PHP AND MySQL", we would split the terms, then use the search clause "WHERE (F_Field LIKE '%PHP%' AND F_Field LIKE '%MySQL%')".

    If you use OR matching, you would just replace the AND with OR. Using mixed AND/OR requires more advanced clauses, using parenthesis to separate. For example, when searching for "PHP AND (MySQL OR Postgres)", the clause would be "WHERE (F_Field LIKE '%PHP%') AND (F_Field LIKE '%MySQL%' OR F_Field LIKE '%Postgres%')"

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    MN
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Wes DeMoney
    I am not familiar with advanced search functionality built into databases, but I can tell you how to handle your AND/OR matching. In your program, you will need to split your keywords by AND/OR, then piece together your search clause accordingly.

    For instance, if the search term is "PHP AND MySQL", we would split the terms, then use the search clause "WHERE (F_Field LIKE '%PHP%' AND F_Field LIKE '%MySQL%')".

    If you use OR matching, you would just replace the AND with OR. Using mixed AND/OR requires more advanced clauses, using parenthesis to separate. For example, when searching for "PHP AND (MySQL OR Postgres)", the clause would be "WHERE (F_Field LIKE '%PHP%') AND (F_Field LIKE '%MySQL%' OR F_Field LIKE '%Postgres%')"
    Thank you for the reply.

    I used to do it like that, but that method is MUCH too slow (on large datasets... It is actually faster on small datasets). Now I want to use a fulltext index with boolean mode enabled (described here: http://dev.mysql.com/doc/mysql/en/Fulltext_Boolean.html), but it defaults to an OR search (too slow for the dataset)....

    I think I will just have to parse the search keywords and make it an AND search at the script level instead of the DB level.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •