Groups | Blog | Home
all groups > sql server programming > march 2007 >

sql server programming : Best way to search one table based on another table's data?


--CELKO--
3/30/2007 5:32:15 PM
[quoted text, click to view]

Do not use SQL at all, but get a textbase product that was built for
this kind of work. But here is one kludge skeleton:


SELECT DISTINCT P.product_id
FROM Keywords AS K, Products AS P
WHERE P.product_name LIKE '%'+ K.keyword +'%'
OR P.product_description LIKE '%'+ K.keyword +'%';

Watch out for upper and lower case, unicode, etc.
Ronald S. Cook
3/30/2007 6:01:01 PM
I have a table of keywords (hundreds/thousands of records):

KeywordID KeywordName
--------- -----------
1 Apple
2 Orange
3 Pear


I then have a table of products (also hundreds/thousands of records):

ProductID ProductName ProductDescription
--------- ----------- ------------------------------------
123 Apple Tree Better than an orange tree, this...
124 Great Scent This great scent smells like orange...


What's the most efficent way to search the entire product table and return
all records that have any of the keywords from the keyword table (in eiter
productname or peoductdescription)?

Thanks,
Ron

Tony Rogerson
3/31/2007 12:00:00 AM
Hi Ron,

Check out Full-Text search in books online.

Tony.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson (Ramblings from the field from a
SQL consultant)
http://sqlserverfaq.com (UK SQL User Community)

[quoted text, click to view]
Tony Rogerson
3/31/2007 12:00:00 AM
[quoted text, click to view]

What - Full Text Search? This is part of the SQL Server product and is
completely integrated into T-SQL.

After 35 years in IT - why did you not know this?

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson (Ramblings from the field from a
SQL consultant)
http://sqlserverfaq.com (UK SQL User Community)

[quoted text, click to view]
Ronald S. Cook
3/31/2007 7:17:23 AM
Thanks.. will do.

[quoted text, click to view]

--CELKO--
3/31/2007 1:05:56 PM
[quoted text, click to view]

I also know it "not ready for prime time"; how many document systems
have you implemented? I have one under my belt for the Labor
Relations legal section of a major untility company, consulting for a
company with an FBI contract (not sure if I want to admit that), and
a few much smaller ones.

And it is not well integrated; it is paste-on to an existing storage
model that does not work well with text. Just as a record is not a
row, a row is not a document. There are no semantic net indexes, no
fuzzy operators. The full text columns have to be kept in a form that
can be read by SQL, instead of a compressed form designed for text
searches.

What they have is an early textbase with a Thesaurus (not maintained
by engine, but by the user), "Noise Word" list kept outside of SQL,
and only simple pattern matching, proximity (not adjustable) and
grammatical forms. An occurence computed on word position within a
row ("foobar is word #42 in row #12") and there are much faster ways
to locate things. Oh, and no quorum operators either.

And it also does not follow either SQL conventions or ANSI/ISO Z39
Standards. In fact, the syntax is really weird and hard for non-
programmers to learn. The real coument users know Lexis, Nexis, West
Law and other similar languages.

If it is all you have and you are not doing serious document searching
and you are a programmer and not an end user, then you can probably
get by. For fun, look up ZyIndex which was the "Gold Standard" for
textbases and see the differences. And there are products that beat
it now.
AddThis Social Bookmark Button