Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Search database

Author  Topic 

albenza
Starting Member

2 Posts

Posted - 2011-12-12 : 04:56:15
Hi,

I have a website where people create their own listings. On this website i have a "simple search" box where a user can type in whatever and search among the listings.

The listings are kept in an SQL server 2008.
A listing contains the following.
Brand name,
Category,
Sub Category,
gender,
Size,
Color,
Item_name,
User_description,


I'm a little confused as to how I will build the query/stored procedure to do the search itself.
As I never know what people will search for, or in what order they will type it in, I can't do a simple select statement. I need to somehow run thru the listings and match the words or something, and then return listings with best match first and desc on matches. Confused. :S

I did a little experimenting, I tried creating another table used for searching only, in this table I have a nvarchar field which contains all relevant/searchable info on the listings (words seperated by ' '). This works if the user search for one word only. (if I do a Like "%searchword%") on this field, but this is not good enough, and not what I want. Been looking into CONTAINS(), but can't seem to get it to works as I would like. I'd like it to just search like this CONTAINS(FIELD, SEARCHSTRING); I picture it going thru all the words in the field and matching them one by one or something. Not working as intended... My logic is flawed on this issue I believe. I need a little guidance to get back on track.

Hope I explained my self good enough, otherwise feel free to ask for the information you need me to provide.

//Edit: Forgot to mention. Speed is also an issue of course...

None

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-12 : 05:49:45
See if this helps
http://beyondrelational.com/blogs/madhivanan/archive/2009/12/14/search-a-value-in-character-column-of-all-tables.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-12-12 : 08:10:27
Ok it is a nice link ,But i attach you another link has 2 options ,Which search and then replace
http://vyaskn.tripod.com/sql_server_search_and_replace.htm
Go to Top of Page

albenza
Starting Member

2 Posts

Posted - 2011-12-13 : 04:57:52
Thnks guys. I'll look into it. :)

None
Go to Top of Page
   

- Advertisement -