?
Solved

Searching using a QueryString

Posted on 2005-04-28
2
Medium Priority
?
168 Views
Last Modified: 2010-04-17
Experts...

I've got a list of headings displayed as links. Each link is a URL that includes a QueryString. For example...

SearchString.asp?Keywords=bkcase wood

When the "SearchString.asp" page is accessed, I'll do a select statemement based on the keywords and "voila", I'll produce a list of products based on the keywords and I'm good to go.

The problem occurs when although there are several products that have "bkcase" and "wood" in their descriptions, I don't get any matches. If I change the Keyword QueryString to just "bkcase" I'll get some matches, but I'm confident that I'm doing something wrong as far as my scripting is concerned, and I'm hoping someone can help me out before 9:00 this morning.
0
Comment
Question by:brucegust
2 Comments
 
LVL 8

Expert Comment

by:doobdave
ID: 13884441
Hi Bruce,

have you tried to output your select statement using trace.writeline or some other method?
I'm just checking to ensure that the select statement that is generated is in fact what you expect it to be.

Reason is, I notice there's a space in the querystring (which is not acceptable), so a browser may be replacing this with an escape sequence ("%20") to make it conform.

Regards,

David

0
 
LVL 1

Accepted Solution

by:
CyberSwine earned 2000 total points
ID: 13885110
In case what doobdave mentioned isn't the problem;
Are you in fact separating the keywords so that each becomes a separate search criteria, or just leaving the string as it is?


Say the keyword "bkcase" resolves to this select statement:

SELECT * FROM Products WHERE Description LIKE '%bkcase%'


Unless you treat the keywords separately, including both keywords might yield:

SELECT * FROM Products WHERE Description LIKE '%bkcase wood%'

This asks the server to return any products whose description include *both* words, in that order. In this example, assuming we're using VBScript, we can do some magic by a simple replace of all instances of " " in the keyword string into "%' OR Description LIKE '%". This would yield:

SELECT * FROM Products WHERE Description LIKE '%bkcase%' OR Description LIKE '%wood%'


So, say your VBScript code says:

"SELECT * FROM Products WHERE Description LIKE '%" & keywords & "%'"

Then you could change that into:

"SELECT * FROM Products WHERE Description LIKE '%" & Replace(keywords, " ", "%' OR Description LIKE '%") & "%'"


Of course you'd have to modify this stuff to fit into your code. Since I haven't seen it I don't know how well this fits in :)


Hope this is of some help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Introduction to Processes
Loops Section Overview

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question