Results 1 to 10 of 14

Thread: SQL Again!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    jmarcv's Avatar
    jmarcv is offline Cranky Coder
    Join Date
    Jan 2005
    Posts
    354

    Wink

    Hmmmmm, did I release that to the public domain?
    Not to complicate issues, but I thought you might be interested.
    REGEXP has an 'or' function (but not an 'and' - bummer -). You can separate each search item with a | (pipe) symbol.

    So rather than looping through the array and creating multiple REGEXP you can create it in one shot outside of your array loop like so:

    PHP Code:
    $strProdNameSearch " concat(' ',pd.products_name,' ') REGEXP '[^a-zA-Z]+".join('[^a-zA-Z]+|[^a-zA-Z]+',$search_keywords)."[^a-zA-Z]+'  "
    This will enhance the speed on searches with numerous search items.

    Also of note, while I took the easy way out:
    \b allows you to perform a "whole words only" search using a regular expression in the form of \bword\b.

    So, I think
    PHP Code:
    REGEXP '[^a-zA-Z]+$search_keywords[$i][^a-zA-Z]+' 
    could also be written as

    PHP Code:
    REGEXP '\b$search_keywords[$i]\b'
     
    $strProdNameSearch " concat(' ',pd.products_name,' ') REGEXP '\b+".join('\b|\b',$search_keywords)."\b'  "
    Last edited by jmarcv; 02-07-2007 at 11:31 AM.

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14