Search multiple keywords across multiple fields

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Search multiple keywords across multiple fields

    Hi,

    I'm about halfway through building a search engine using ASP, SQL and
    Access.
    As part of that search engine I need to search multiple keywords across
    multiple fields
    So far I've figured out how to split a string into words. From here I could:

    Construct an SQL statement of varying length that, using the LIKE and AND
    operators. This seems damn hard!

    Alternately I could concatenate the multiple fields into a variable or array
    then search.

    What is best - can anyone provide examples ?

    Darren


    Darren Heinrich Guest

  2. Similar Questions and Discussions

    1. One Search String/Multiple Fields
      Hello! What I am trying to do is create a query page for my users that allows them to enter one search string (var=#string#) and then click...
    2. PHP MySQL search same name in multiple dbase fields
      How do I search two fields (e.g., "lastName" and "maidenName") using one name (but can be more than 1 word) so one can find a record for a woman for...
    3. ANN: InterAKT Site Search - search in multiple tables
      Hello, We have just released a new product, MX Site Search, meant to help web developers and designers create a search form in their dynamic...
    4. SQL Search Multiple Fields ??
      James wrote: Yes. Well, just execute this SQL statement using the PHP extension for the SQL server you're using. By the way: how does...
    5. Access Combo Box search allowing seacr on multiple fields
      Question: In a table the first field is the Customer number and the second field is the Customer name. I want to create a single combo box so it...
  3. #2

    Default Re: Search multiple keywords across multiple fields

    Perhaps something like this might give you some ideas:

    If KeywordFromDlg <> "" Then
    strSQLWhere = strSQLWhere & " AND ("
    strSQLWhere = strSQLWhere & " (1<>1)"
    strSQLWhere = strSQLWhere & " OR (Title Like " & Chr(39) & "%" &
    KeywordFromDlg & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
    KeywordFromDlg & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
    KeywordFromDlg & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & ")"
    End If

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    [url]http://www.Bullschmidt.com[/url]
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt Guest

  4. #3

    Default Re: Search multiple keywords across multiple fields

    Gosh not sure I understand all that - can you break it down for me please ?

    Thanks

    Darren

    "Bullschmidt" <paul@bullschmidt.com-nospam> wrote in message
    news:%23a6G%23E36DHA.1556@tk2msftngp13.phx.gbl...
    > Perhaps something like this might give you some ideas:
    >
    > If KeywordFromDlg <> "" Then
    > strSQLWhere = strSQLWhere & " AND ("
    > strSQLWhere = strSQLWhere & " (1<>1)"
    > strSQLWhere = strSQLWhere & " OR (Title Like " & Chr(39) & "%" &
    > KeywordFromDlg & "%" & Chr(39) & ")"
    > strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
    > KeywordFromDlg & "%" & Chr(39) & ")"
    > strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
    > KeywordFromDlg & "%" & Chr(39) & ")"
    > strSQLWhere = strSQLWhere & ")"
    > End If
    >
    > Best regards,
    > J. Paul Schmidt, Freelance ASP Web Developer
    > [url]http://www.Bullschmidt.com[/url]
    > ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Darren Heinrich Guest

  5. #4

    Default Re: Search multiple keywords across multiple fields

    Example of searching for keywords separately for each word on multiple
    fields. For example with Keywords of Go Back Now one gets the SQL Where
    clause of ((Title Like '%Go%') OR (Category Like '%Go%') OR (Descr Like
    '%Go%')) OR ((Title Like '%Back%') OR (Category Like '%Back%') OR (Descr
    Like '%Back%')) OR ((Title Like '%Now%') OR (Category Like '%Now%') OR
    (Descr Like '%Now%')):

    'Keywords = Request.Form("Keywords")
    Keywords = "Go Back Now"

    ' Set var.
    KeywordsFixedForSQL = Keywords

    ' Remove any ".
    KeywordsFixedForSQL = Replace(KeywordsFixedForSQL, Chr(34), "")

    ' Double up any single quotes.
    KeywordsFixedForSQL = Replace(KeywordsFixedForSQL, "'", "''")

    If KeywordsFixedForSQL <> "" Then
    ' Set var (array of words).
    strarrayKeywordsFixedForSQL = Split(KeywordsFixedForSQL, " ")

    ' Loop thru items (words).
    For intItemNum = 0 To UBound(strarrayKeywordsFixedForSQL)
    strSQLWhere = strSQLWhere & " OR ("
    strSQLWhere = strSQLWhere & "(Title Like " & Chr(39) & "%" &
    strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
    strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
    strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
    strSQLWhere = strSQLWhere & ")"
    Next ' Next intItemNum.

    ' Remove initial " OR ".
    strSQLWhere = Right(strSQLWhere, Len(strSQLWhere) - 4)
    End If

    Response.Write "strSQLWhere: " & strSQLWhere & "<br><br>"

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    [url]http://www.Bullschmidt.com[/url]
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt Guest

Posting Permissions

  • You may not post new threads
  • You may 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139