|
Question : Customizing a SQL Contains statement for performance.
|
|
I had an issue a while back with MSSQL 2008 not returning all the results necessary. Here's what I had done: Sql was not ruturning all the results I wanted in a Contains statement. An example is: ***************** SELECT TOP 20 UserName, ItemName, ItemPrice, ItemLogo, merchantCategory, ItemKey, Clicks, UserScore, International, ItemURL FROM Items WHERE Active='1' AND CONTAINS(ItemName, 'FORMSOF (THESAURUS, "doggie treats")') ORDER BY Cleaned DESC, Clicks DESC, Commission DESC **************************** Looks great right? Unless a person was to type "treats doggie" (reversed) or Pooch doggie treats, nothing would show up in results because Contains wasn't set to search for each word within the string. Only synchronous strings. I fixed this problem by using a split command on the input string with a custom sql statement like: ****************************** "SELECT TOP 20 UserName, ItemName, ItemPrice, ItemLogo, merchantCategory, ItemKey, Clicks, UserScore, International, ItemURL FROM Items WHERE Active='1' AND CONTAINS(ItemName, 'FORMSOF (THESAURUS, " & SplitArray(0) & ")') AND CONTAINS(ItemName, 'FORMSOF (THESAURUS, " & SplitArray(1) & ")') ORDER BY Cleaned DESC, Clicks DESC, Commission DESC") ********************************* You can see for yourself at www.WebSpider.com and see it works fine. However, the problem now is performance.... I believe the extra Contains is causing a timeout in the wordbreaker throwing up a nasty message. Is there any way I can revert back to my old SELECT syntax and use some sort of wildcards or set the sql server to broaden it's results? Please help. Thanks, Chris.
|
|
Answer : Customizing a SQL Contains statement for performance.
|
|
Why not just try a simple:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
|
SELECT TOP 20
UserName,
ItemName,
ItemPrice,
ItemLogo,
merchantCategory,
ItemKey,
Clicks,
UserScore,
International,
ItemURL
FROM Items
WHERE Active = '1'
AND CONTAINS(ItemName, '"doggie and treats"')
ORDER BY
Cleaned DESC,
Clicks DESC,
Commission DESC
|
|
|
|
|