SQL server 2008 - storing and searching URL (web address)
I'm facing a decision on how to store URL (bookmark) in a table. I have following requirements:
Customer must be able to search the title of a bookmark.
I decided to use a FTS with ranking option for this requirement
Customer must be able to search an address
Here is where I have doubts on how to store URL. First of all, URLs must be unique in my table. This will potentially be a very large table. There will be no updates or deletes on this table. What I had in mind is this
ID [int] IDENTITY(1,1) -- identity and foreign key in other table(s)
Title [nvarchar](500) -- title (FTS)
CompleteURL [nvarchar](300), -- Unique index example: http://www.bbc.co.uk
URLPrefix [nvarchar](20), -- example: http://www
URLSufix [nvarchar](280), -- example: bbc.co.uk/something (index)
I realize I have data duplication but I have no problem with that since data integrity is not at stake here (no updates or deletes) and performance is important. I was thinking to use CompleteURL as my IF EXISTS column during insert. I'm not sure if this approach will provide better performance than composite key on URLPrefix and URLSufix and to completely lose CompleteURL?
URLSufix would provide quick开发者_Python百科 find for search parameter LIKE 'bbc%'.
But what if customer does search LIKE 'www.bbc%' ? Any wildcards on beginning of a string (%bbc%) are out of the question since I cannot afford scan of entire table.
Furthermore, i decided to move URLs longer than (300) in another table since there more than 99.9% of URLs are not that long and I don't want to hit the index limit of 900 bytes. Is this a good practice?
EDIT:
To make a long story short. How would you store this bookmark
BBC Homepage title
http://www.bbc.co.uk/
if you want it to be returned when search parameter is one of 3 cases:
1. 'homepage'
2. 'bbc.co'
3. 'www.bbc.co'
1) If you are using SQL Server 2005 (or SQL Server 2008 / 2008 R2), you can configure the full text search functionality on the URL columns, so you can avoid using the LIKE operator as a whole (event %bbc% will take much less time now).
Now, if you have configured full-text search on title,and complete URL, you can use contains clause of SQL to search what you are looking for.
精彩评论