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
 General SQL Server Forums
 New to SQL Server Programming
 How do I write a logic for 'SEARCH' criteria

Author  Topic 

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-08-15 : 23:16:04
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

52326 Posts

Posted - 2012-08-15 : 23:18:59
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

81 Posts

Posted - 2012-08-16 : 00:08:11
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
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-08-16 : 01:45:55
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

81 Posts

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

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-08-16 : 15:30:04
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

81 Posts

Posted - 2012-08-16 : 19:00:25
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
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-08-17 : 09:05:58
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

81 Posts

Posted - 2012-08-23 : 03:28:11
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
   

- Advertisement -