| 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 likeSELECT * FROM table WHERE Field LIKE '%' + REPLACE(@Word,' ','%') + '%' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 |
 |
|
|
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 resultsJack Vamvas--------------------http://www.sqlserver-dba.com |
 |
|
|
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. |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
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 |
 |
|
|
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 restselect '''%' + 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 isscenario, If I have been searching for a statement 'video boys', and the table which is searching for those keywords have 2 records as BoysVideo BoysIt should return, as below Video BoysBoysto implement above would there be a tactic to get it on topThanks,AB |
 |
|
|
|