Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Databases > Access   »   Search Single Word

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Jul 23, 2008, 11:22 PM
faeizal
New Member
faeizal is offline
 
Join Date: Jul 2008
Posts: 1
faeizal See this member's comment history on his/her Profile page.
Search Single Word

Dear Expert,

I was using the following scripts to search my articles database. But in the operating, I found a difficult work to make this script could find a singgle word. For example, I'm searching text for "COAL" only in the keyword box.. but in the search results, the are the unwanted articles also included into the results display such "coalition, coalesce, etc..". My question is, how to make the script would work to find the only "COAL" in the articles? I want to "ignore" the others.

Here is a part of the script:

---------------------------------------------------------------------------------

If Request.QueryString("PagePosition") = "" Then
intRecordPositionPageNum = 1

Else
intRecordPositionPageNum = CInt(Request.QueryString("PagePosition"))
End If

strSearchKeywords = Trim(Request.QueryString("search"))

If strSearchKeywords = "" Then strSearchKeywords = chr(10)

strSearchKeywords = Replace(strSearchKeywords, "<", "&lt;")
strSearchKeywords = Replace(strSearchKeywords, ">", "&gt;")
strSearchKeywords = Replace(strSearchKeywords, "'", "''")

sarySearchWord = Split(Trim(strSearchKeywords), " ")

strSearchKeywords = Replace(strSearchKeywords, "''", "'")

blnSearchWordLenthOK = True

For intLoopCounter = 0 To UBound(sarySearchWord)

intSearchWordLength = Len(sarySearchWord(intLoopCounter))

If intSearchWordLength <= intMinuiumSearchWordLength Then
blnSearchWordLenthOK = False
End If
Next

Set rsSearchResults = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT tblNews.* FROM tblNews "

Select Case Request.QueryString("mode")

Case "anywords"

strSQL = strSQL & "WHERE News_title LIKE '%" & sarySearchWord(0) & "%'"
For intSQLLoopCounter = 0 To UBound(sarySearchWord)
strSQL = strSQL & " OR News_title LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
strSQL = strSQL & " OR News_Item LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
strSQL = strSQL & " OR Short_News LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
Next
strSQL = strSQL & " ORDER By News_ID DESC;"

Case "allwords"

strSQL = strSQL & "WHERE (News_title LIKE '" & sarySearchWord(0) & "'"
For intSQLLoopCounter = 0 To UBound(sarySearchWord)
strSQL = strSQL & " AND News_title LIKE '" & sarySearchWord(intSQLLoopCounter) & "'"
Next

strSQL = strSQL & ") OR (News_Item LIKE '%" & sarySearchWord(0) & "%'"
For intSQLLoopCounter = 1 To UBound(sarySearchWord)
strSQL = strSQL & " AND News_Item LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
Next

strSQL = strSQL & ") OR (Short_News LIKE '" & sarySearchWord(0) & "'"
For intSQLLoopCounter = 0 To UBound(sarySearchWord)
strSQL = strSQL & " AND Short_News LIKE '" & sarySearchWord(intSQLLoopCounter) & "'"
Next

strSQL = strSQL & ") ORDER By News_ID DESC;"

Case "new"

strSQL = "SELECT TOP " & intRecordsPerPage & " tblNews.* FROM tblNews"
strSQL = strSQL & " ORDER By News_ID DESC;"
End Select

---------------------------------------------------------------------------------

Thank you for helping

Faeizal

Reply With Quote
 
     

Answers
 
 
Old Jul 24, 2008, 05:03 AM   #2  
ScottGem
Computer Expert
ScottGem is offline
 
ScottGem's Avatar
 
Join Date: Jan 2003
Location: LI, NY - USA
Posts: 22,612
ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.
Pay to call ScottGem for advice ($.75/min)
Call ScottGem via Skype™
The problem isn't really your code. The % character is a wildcard, so When you search on %coal%, you are searching for that 4 letter string anywhere in the field. Which is why you are getting those results.

What you can do is add a flag for whole word. This would then add leading and trailing spaces. Of course this presents a different problem if the word is at the beginning of the field or the end of a sentence (so its followed by a period).

You can try testing the results using the Instr function to determine the starting point of your search string then test the preceeding and following characters using the MID function.
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
add a word and its meaning to ms word dictionary Anithaprasadv Word Processing 2 Apr 4, 2008 07:20 AM
lotus word to microsoft word leotan Other Software 2 Oct 13, 2006 05:40 AM
MS Word - multiple instances of the same word? pburani Word Processing 1 Nov 11, 2004 07:30 AM
Adding a word and its meaning to Word Dictionary saivstech Word Processing 4 Jul 4, 2003 03:51 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 07:05 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.