ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 8th, 2008, 11:32 AM
tumby1974 tumby1974 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 7 tumby1974 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 31 m 41 sec
Reputation Power: 0
Multiple keyword search for one field

I have one search field that the user can put in several words (separated by space). I would like to break this string up and query the table on all the words from this string. For example, if the user enters "Doe Smith Johnson Williams", I want to search the table and pull up all records with Last Name = Doe AND Smith AND Johnson AND Williams.

I've searched and found several examples, but they are all in php. I've tried to convert to asp but it doesn't seem to be working.

Also this php code I used was based off of searching more than one column (field?) So I was also trying to eliminate the multiple column part of the code, and just have it search off of one field.

PHP Code:
 dim keywords(20)
    
dim Lnamestring
  
 
    dim search_columns
(1)
    
search_columns(0)="LName" 'this was  where you would put multiple search columns...i just stuck my one in there  
  
    Lnamestring = CCGetFromGet("s_LName", Empty)
    
    Lnamestring = trim(Lnamestring)

    keywords = split(Lnamestring)
      
    Employee2.datasource.Where = " "  
  
    dim p
    p = 0
      
    Employee2.DataSource.Where = Employee2.DataSource.Where & "("
    dim word
    dim m
    dim column
    for each word in keywords
          if (len(word) > 2) then  
          if (p <> 0) then 
           Employee2.DataSource.Where = Employee2.DataSource.Where & ") AND ("  
           p=1  
           m=0
          end if 
          for each column in search_columns
            if (m <> 0) then 
              Employee2.DataSource.Where = Employee2.DataSource.Where & " OR "  
              Employee2.DataSource.Where = Employee2.DataSource.Where & " column LIKE '
%word%' "  
              m=1
            end if
          
          next '
end foreach column  
           end 
if
      
    
next ' foreach word  
    Employee2.DataSource.Where = Employee2.DataSource.Where & ")" 

Reply With Quote
  #2  
Old May 8th, 2008, 02:27 PM
tumby1974 tumby1974 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 7 tumby1974 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 31 m 41 sec
Reputation Power: 0
I found a simpler looking piece of code on this forums, and tried to implement it. But it still isn't working:

PHP Code:
 dim term
dim x
dim clause
dim Lnamestring

Lnamestring 
CCGetFromGet("s_LName", Empty)

If 
Len(Lnamestring) > 0 Then
    
'term = Trim(Request.Form("search"))
    term = Trim(Lnamestring)
    
    If InStr(term," ") > 0 Then
        term = Split(term," ")
        
        For x=0 to Ubound(term)
            If x > 0 Then
                    clause = clause & " AND"
                End If
            clause = clause & " LName LIKE '
%" & term(x) & "%'"
        Next
    Else
        clause = " LName LIKE '
%" & term & "%'"
    End If
    
    
    Employee2.DataSource.Where = Employee2.DataSource.Where & clause
    
End If 


CCGetFromGet() pulls the string from the URL when the search button is pressed, and dumps it in Lnamestring. The last line just adds the clause info to the sql query (I'm using CodeCharge Studio)

Reply With Quote
  #3  
Old May 8th, 2008, 02:40 PM
tumby1974 tumby1974 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 7 tumby1974 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 31 m 41 sec
Reputation Power: 0
Well, I have it working - sort of. If I have 4 search items, it's only bringing up 3. It's always bringing up n-1 items.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Multiple keyword search for one field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway