Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Full-Text Search / July 2004

Tip: Looking for answers? Try searching our database.

containstable across columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John C - 09 Jul 2004 21:29 GMT
We're having some difficulty getting adequate search results.  We're trying to search across 3 columns, "author", "title", and "subtitle" (no other columns are part of FT index).  The problem relates to searching for an author/title phrase at the same time.  Say the user types "chemistry brown" into a search box, (the Author being "Brown" and the title "Chemistry"--but there's no way to make that distinction at run time).  If you use CONTAINSTABLE, (...from containstable(<ourtable>,*,'"brown" near "chemistry"') it only return rows where "brown" and "chemistry" are in the SAME column (where what we need is for it to return high rankings where "brown" and "chemistry" are in different columns but the same rows).   Freetexttable is no better, since again it's ranking based on the number of occurrences of a word in a SINGLE column, not in all the FT-indexed columns per row.
The key factor is that the type of word (author, title, subtitle) is not known at search time, which it difficult.  Any suggesstions?

Platform: SQl 2K sp3, Windows Server 2000 Sp4
Hilary Cotter - 11 Jul 2004 04:03 GMT
you could try this

select * from containstable(fulltext,*,'chemistry or brown')

or

select * from containstable(fulltext,*,'"chemistry" or "brown"')

Signature

Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html

> We're having some difficulty getting adequate search results.  We're trying to search across 3 columns, "author", "title", and "subtitle" (no
other columns are part of FT index).  The problem relates to searching for
an author/title phrase at the same time.  Say the user types "chemistry
brown" into a search box, (the Author being "Brown" and the title
"Chemistry"--but there's no way to make that distinction at run time).  If
you use CONTAINSTABLE, (...from containstable(<ourtable>,*,'"brown" near
"chemistry"') it only return rows where "brown" and "chemistry" are in the
SAME column (where what we need is for it to return high rankings where
"brown" and "chemistry" are in different columns but the same rows).
Freetexttable is no better, since again it's ranking based on the number of
occurrences of a word in a SINGLE column, not in all the FT-indexed columns
per row.
> The key factor is that the type of word (author, title, subtitle) is not known at search time, which it difficult.  Any suggesstions?
>
> Platform: SQl 2K sp3, Windows Server 2000 Sp4
John Kane - 12 Jul 2004 07:19 GMT
Hilary,
While the below containstable query examples provide a solution, it does not
meet John's requirement of  'search across 3 columns, "author", "title", and
"subtitle"' and I submit that using the following FT-enabled Northwind table
(Employees) and multiple column specific column names (vs. using "*" or
asterisk for all FT-enabled columns) does meet John's request, for example:

use Northwind
go
SELECT LastName, FirstName, Title, Notes from Employees
/* returns:
LastName             FirstName  Title
-------------------- ---------- ------------------------------
Davolio              Nancy      Sales Representative
Fuller               Andrew     Vice President, Sales
Leverling            Janet      Sales Representative
Peacock              Margaret   Sales Representative
Buchanan             Steven     Sales Manager
Suyama               Michael    Sales Representative
King                 Robert     Sales Representative
Callahan             Laura      Inside Sales Coordinator
Dodsworth            Anne       Sales Representative
(9 row(s) affected)
*/

-- an expanded version of your example. Note, that this query will return
all 9 rows that contain Fuller (LastName column) OR Sales (Title column)
SELECT e.LastName, e.FirstName, e.Title
  from Employees AS e,
  containstable(Employees,*,'Fuller or Sales') as A
      where
        A.[KEY] = e.EmployeeID

--or this example that will also return all 9 rows that contain Fuller
(LastName column) OR Sales (Title column)
SELECT e.LastName, e.FirstName, e.Title
  from Employees AS e,
  containstable(Employees,*,'"Fuller" or "Sales"') as A
      where
        A.[KEY] = e.EmployeeID

However, John wants to 'search across 3 columns, "author", "title", and
"subtitle"' and the user types "chemistry brown" into a search box, (the
Author being "Brown" and the title "Chemistry"). Note the request is for an
AND'ing between the FT-enabled columns and not an OR between the columns.
This can be satsified via using multiple CONTAINSTABLE clauses and AND'ing
the join between Containstable predicates, for example

SELECT e.LastName, e.FirstName, e.Title
  from Employees AS e,
    containstable(Employees, LastName, 'Fuller') as A,
    containstable(Employees, Title, 'Sales') as B
      where
        A.[KEY] = e.EmployeeID AND
        B.[KEY] = e.EmployeeID
go
/* -- returns:
LastName             FirstName  Title
-------------------- ---------- ------------------------------
Fuller               Andrew     Vice President, Sales
*/

John, you can also use the workarounds that are documented for this issue in
SQL Server 7.0 KB article "286787 (Q286787) FIX: Incorrect Results From
Full-Text Search on Several Columns" at
http://support.microsoft.com/default.aspx?scid=kb;en-us;286787 as well as
SQL Server 7.0 KB article "294809 (Q294809) FIX: Full-Text Search Queries
with CONTAINS Clause Search Across Columns" at
http://support.microsoft.com/default.aspx?scid=kb;en-us;294809. You should
note that while these SQL Server 7.0 specific KB articles are "fixes" for
SQL Server 7.0, this is the default behavior for SQL Server 2000 and SQL
Server 7.0 was "fixed" to comply with the default behavior of SQL Sever
2000. The workarounds in the KB articles will also work in SQL Server 2000
as well as the above solution that I provided above.

Regards,
John

> you could try this
>
[quoted text clipped - 21 lines]
> >
> > Platform: SQl 2K sp3, Windows Server 2000 Sp4
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.