SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mysql, regular expressions and php

    I'm trying to write an application that search a database for words. Easy I know but the problem I have is that I need to find just whole words. So for example if I search for "port" I don't get returned match's for support and sport. I also have to take in to account any punctuation in the text.

    I have been trying to do this within mysql using regexp. Is this the best way? Here is the sql statement I'm using in my script:

    SELECT * FROM portfolio WHERE intro REGEXP '\[ .,:;?!\'\"-_\(\)\&\$\%]$k_search\[ .,:;?!\'\"-_\(\)\&\$\%]';

    where portfolio is the table name and intro the column. intro is of type text.

    Would it be better to take all the data out of the database and use php to do the search? I thought about this but I was worried about the speed implications.

    Any help would be greatly received.

    lorez

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not positive, but I think you are correct about the query approach probably being stronger than pulling an entire set of records into php memory.

    However, check out this most excellent thread for an alternate route: designing a search engine for a large forum?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers samsm, I'll work through it.

    You don't know any good resources for regular expressions do you? I tend to glaze over when I get too deep into them and my sleep becomes affected.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There's always this SitePoint article.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did manage to work this help. If anyone is interested the regular expression needed was:

    (^|[^a-z])$k_search($|[^a-z])


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
  •