Upgrading a Search Procedure

i have an sp that does not use full text searching in SQL 2000 i was wondering if someone could point me in the right direction of changing/upgrading this to a full text search would you recommend upgrading the search sp the following is the sp i have(it uses a function to count the number of words):

CREATE PROCEDURE SearchCatalog
(
@PageNumber tinyint,
@ProductsOnPage tinyint,
@HowManyResults smallint OUTPUT,
@AllWords bit,
@Word1 varchar(15) = NULL,
@Word2 varchar(15) = NULL,
@Word3 varchar(15) = NULL,
@Word4 varchar(15) = NULL,
@Word5 varchar(15) = NULL)
AS

/* Create the temporary table that will contain the search results */
CREATE TABLE #SearchedProducts
(RowNumber SMALLINT NOT NULL IDENTITY(1,1),
 ProductID INT,
 Name VARCHAR(100),
 Description VARCHAR(1000),
 Price MONEY,
 ImagePath VARCHAR(100),
 Rank INT,
 ImageALT VARCHAR(100),
 ArtistName VARCHAR(50),
 Stock INT,
 SearchCoverQuality INT,
 SearchAlbumQuality INT)

/* Populate #SearchedProducts for an any-words search */
IF @AllWords = 0
   INSERT INTO #SearchedProducts
          (ProductID, Name, Description, Price, ImagePath, ImageALT, ArtistName, Stock, SearchCoverQuality, SearchAlbumQuality, Rank)
   SELECT Product.ProductID, Product.Name, Product.Description, Product.Price, Product.ImagePath,
            Product.ImageALT, Artist.ArtistName, Product.Stock, AlbumSingleDetails.CoverQualityID, AlbumSingleDetails.QualityID,
          3*dbo.WordCount(@Word1, Name)+dbo.WordCount(@Word1, Description)+dbo.WordCount(@Word1, ArtistName)+
          3*dbo.WordCount(@Word2, Name)+dbo.WordCount(@Word2, Description)+dbo.WordCount(@Word2, ArtistName)+
          3*dbo.WordCount(@Word3, Name)+dbo.WordCount(@Word3, Description)+dbo.WordCount(@Word3, ArtistName)+
          3*dbo.WordCount(@Word4, Name)+dbo.WordCount(@Word4, Description)+dbo.WordCount(@Word4, ArtistName)+
          3*dbo.WordCount(@Word5, Name)+dbo.WordCount(@Word5, Description)+dbo.WordCount(@Word5, ArtistName)
          AS TotalRank
   FROM Product INNER JOIN (Artist INNER JOIN AlbumSingleDetails ON Artist.ArtistID = AlbumSingleDetails.ArtistID) ON Product.ProductID = AlbumSingleDetails.ProductID
   ORDER BY TotalRank DESC
  

/* Populate #SearchedProducts for an all-words search */
IF @AllWords = 1
   INSERT INTO #SearchedProducts
          (ProductID, Name, Description, Price, ImagePath, ImageALT, ArtistName, Stock, SearchCoverQuality, SearchAlbumQuality, Rank)
   SELECT Product.ProductID, Product.Name, Product.Description, Product.Price, Product.ImagePath,
   Product.ImageALT, Artist.ArtistName, Product.Stock, AlbumSingleDetails.CoverQualityID, AlbumSingleDetails.QualityID,
          (3*dbo.WordCount(@Word1, Name)+dbo.WordCount(@Word1, Description)+dbo.WordCount(@Word1, ArtistName)) *
          CASE
             WHEN @Word2 IS NULL THEN 1
             ELSE 3*dbo.WordCount(@Word2, Name)+dbo.WordCount(@Word2, Description)+dbo.WordCount(@Word2, ArtistName)
          END *
          CASE
             WHEN @Word3 IS NULL THEN 1
             ELSE 3*dbo.WordCount(@Word3, Name)+dbo.WordCount(@Word3, Description)+dbo.WordCount(@Word3, ArtistName)
          END *
          CASE
             WHEN @Word4 IS NULL THEN 1
             ELSE 3*dbo.WordCount(@Word4, Name)+dbo.WordCount(@Word4, Description)+dbo.WordCount(@Word4, ArtistName)
          END *
          CASE
             WHEN @Word5 IS NULL THEN 1
             ELSE 3*dbo.WordCount(@Word5, Name)+dbo.WordCount(@Word5, Description)+dbo.WordCount(@Word5, ArtistName)
          END
          AS TotalRank
   FROM Product INNER JOIN (Artist INNER JOIN AlbumSingleDetails ON Artist.ArtistID = AlbumSingleDetails.ArtistID) ON Product.ProductID = AlbumSingleDetails.ProductID
   ORDER BY TotalRank DESC

/* Save the number of searched products in an output variable */
SELECT @HowManyResults=COUNT(*) FROM #SearchedProducts WHERE Rank>0

/* Send back the requested products */
SELECT ProductID, Name, Description, Price, ImagePath, ImageALT, ArtistName, Stock, Rank,
        CASE SearchCoverQuality
            WHEN 1 THEN '5stars.gif'
            WHEN 2 THEN '4stars.gif'
            WHEN 3 THEN '3stars.gif'
            WHEN 4 THEN '2stars.gif'
            ELSE '1stars.gif'
        END AS CoverQuality,
        CASE SearchAlbumQuality
            WHEN 1 THEN '5stars.gif'
            WHEN 2 THEN '4stars.gif'
            WHEN 3 THEN '3stars.gif'
            WHEN 4 THEN '2stars.gif'
            ELSE '1stars.gif'
        END AS AlbumQuality
FROM #SearchedProducts
WHERE Rank > 0
  AND RowNumber BETWEEN (@PageNumber-1) * @ProductsOnPage + 1
                    AND @PageNumber * @ProductsOnPage
ORDER BY Rank DESC

i was wondering if i can use full text search on many tables at once

thanks in advance!

TuppersBig Smile




Answer this question

Upgrading a Search Procedure

  • quan170165

    Yes, you can use fulltext to simplify the search. You can fulltext index many tables but you have to query each one separately. You can however query multiple indexed columns in a table easily. To combine results from multiple tables you can use UNION operator. There are samples in Books Online that will help. Look at topics like CONTAINS, FREETEXT, CONTAINSTABLE etc.

  • Upgrading a Search Procedure