sql server 2005 - SQL Keyword search algorithm: This SQL does a sequential search, how to do an indexed search? -


we have 3 tables hold our products , keywords:

product {int id, string name, ...} productkeyword {int productid, int keywordid} keyword {int id, string keyword} 

this sql code returns relevant products least relevant products having keywords users search criteria. searchwordtable table of search words. @keywordcount count of search words. returns products having 1 or more keywords, ordered quantity of keywords found each product.

select productid, productname, count(*) * 1 / @keywordcount percentrelevant (select keyword, productid, productname         product              join productkeyword on ...               join keyword on ...              join searchwordtable on searchwordtable.keyword                    '%' + keyword.keyword + '%') k -- join aweful group productid, productname order percentrelevant desc -- relevant first 

the problem sequential search comparing every keyword have. it's not bad, searches can take minute million records.

how rewrite query not use like, use indexed search, , similar results? use like partial matches, e.g., 'bone' in 'boneless'.

links better sql algorithms surely appreciated.

like killing you, leading wildcard removes indexes columns may have.

you should using sql server's full-text indexing. contains faster , far more powerful partial matches of nature appear doing.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -