SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Fender963's Avatar
    Join Date
    Dec 2003
    Location
    Texas
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Full Text Search help...

    Hey Guys,
    Is it possible with PHP Full text search to find all results where all keywords are found but they dont' have to be within the same row?

    For example say I have the following two entries in my database:

    Product_name: Joe's Dog Stuff
    Prodcut_description: Contains food and toys.

    Product_name: Cat food
    Product_description: Some toys and stuff.

    If the user entered the search phrase dog food, it shoudl only find the first one because it has both dog and food jsut not in the same row.

    Thank you,
    Kyle

  2. #2
    SitePoint Zealot shaman's Avatar
    Join Date
    Feb 2005
    Location
    W.R. Home
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to create fulltext index for the fields where you want to do the search.
    I mean something like this

    Code:
    ALTER TABLE your_table ADD FULLTEXT ( your_field );
    only after this you can do a fulltext search, but it looks a bit differ then common select. like this
    Code:
    SELECT * FROM your_table WHERE MATCH( your_field ) AGAINST('what do you search for');
    visit www.mysql.com for more details and examples
    She's my german fraulein

  3. #3
    SitePoint Zealot shaman's Avatar
    Join Date
    Feb 2005
    Location
    W.R. Home
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just remembered, if you need just check if one of the wolds exists, you could split the search string on separated words manually and then use regular expressions to check your database. Something like this

    Code:
    SELECT * FROM your_table WHERE Product_name REGEXP 'dog|food'
    She's my german fraulein


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
  •