SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do I write a logic for 'SEARCH' criteria
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 08/15/2012 :  23:16:04  Show Profile  Reply with Quote
Good Morning my Excellent Guys,

I have been asked to write a SEARCH task, in SQL where when I search for a particular word, it should bring in the most relevant searches ordered from top to bottom.

For instance If I search a book for Accounting and Finance, it should bring in books for Accounting and Finance solely, Finance solely, and then Accounting also solely.

Thank you for reading my post.

Thanks,

AB.

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 08/15/2012 :  23:18:59  Show Profile  Reply with Quote
sounds like wildcard search to me

like

SELECT * FROM table WHERE Field LIKE '%' + REPLACE(@Word,' ','%') + '%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 08/16/2012 :  00:08:11  Show Profile  Reply with Quote
Hi Visak and the rest of the others.,

Thank you for fast response, what I really need is for instance, if I put Accounting Finance in the search bar, it shold bring in accounting finance on top going below also if it has the same keywords, and after those, it should bring in accounting only in the search and then finance as the ohter.

In the above listed I would only get for the keywords which I have put, if it is accounting and finance, then accounting and finance, not finance solely nor accounting solely, how can I add those on to that too.

Thanks,

AB
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1765 Posts

Posted - 08/16/2012 :  01:45:55  Show Profile  Visit jackv's Homepage  Reply with Quote
Are you passing the search terms in as an array? You may need to do some string manipulation of the @search to break them down.
One method I've used is CONTAINSTABLE . This method can Rank your results

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 08/16/2012 :  02:41:09  Show Profile  Reply with Quote
I have got no idea on what is happening in the front end coding.
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1765 Posts

Posted - 08/16/2012 :  15:30:04  Show Profile  Visit jackv's Homepage  Reply with Quote
Firstly find out if you can create an array - this will give you some flexibility in the approach for your SQL statement .
Are you planning on using a stored procedure? If so , you'll probably have sufficient control the approach.

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 08/16/2012 :  19:00:25  Show Profile  Reply with Quote
I would like to work with only from the perspective of the SQL server, cause I am a SQL developer / Administrator, and have given the task to do by myself, pertaining only the backend.
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1765 Posts

Posted - 08/17/2012 :  09:05:58  Show Profile  Visit jackv's Homepage  Reply with Quote
OK, if you post the DDL and DML of your attempt , we can assist in refining your process.

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 08/23/2012 :  03:28:11  Show Profile  Reply with Quote
The below are the coding which I have done, please note that I have to get the most number of keywords on top and then the rest


select '''%' + replace(replace(@search,' and ','%'' and table like ''%'),' or ', '%'' or table like ''%')+'%'''
select '''%' + replace(@search,' ','%'' or table like ''%')+'%'''

I have got something else also which is relevant from this to ask for, which is

scenario, If I have been searching for a statement 'video boys', and the table which is searching for those keywords have 2 records as

Boys
Video Boys

It should return, as below

Video Boys
Boys

to implement above would there be a tactic to get it on top


Thanks,

AB
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000