CONTAINSTABLE问题

时间:2015-06-18 19:41:56

标签: sql sql-server

我已在我的数据库中设置了全文索引以及CONTAINSTABLE,因此用户可以在网站上搜索产品SKU&产品名称。我已经在搜索上设置了一个自定义,它在用户搜索中删除了连字符( - ),并在数据库列中抓取值。我在搜索问题上遇到了问题,搜索
 10-10'导致页面损坏,错误列表如下:

Source:.Net SqlClient Data Provider
Message:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Stack Trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)

搜索效果不错,我知道这不应该是一个问题,因为如果我搜索了tw5-c'我得到了一些结果。是否可能返回太多结果并且连接超时?

这是SQL CONTAINSTABLE语句:

INSERT @searchfilter (productid, variantID, SearchRank)
        SELECT p.ProductID, pv.VariantID, 100 from dbo.Product p with(NOLOCK)
            JOIN dbo.ProductVariant pv with(NOLOCK) on p.ProductID = pv.ProductID 
                JOIN dbo.ProductStore ps with(NOLOCK) on p.ProductID = ps.ProductID and ps.StoreID = @storeID
                WHERE 
                ( REPLACE(p.SKU,'-','') LIKE '%' + @searchstr + '%' )
                OR
                ( REPLACE(p.Name,'-','') LIKE '%' + @searchstr + '%' )
        UNION
        SELECT p.ProductID, pv.VariantID,
               case
                    when psearch.[KEY] is not null then psearch.Rank
                    when pvsearch.[KEY] is not null then pvsearch.Rank
                    else 1
                end
                as SearchRank
            from dbo.Product p with(NOLOCK)
            JOIN dbo.ProductVariant pv with(NOLOCK) on p.ProductID = pv.ProductID
            -- fulltext indexing changes for more accurate searches
            join CONTAINSTABLE(Product, *, @ftssearchstring) psearch ON p.ProductID = psearch.[KEY]
            left join CONTAINSTABLE(ProductVariant, *, @ftssearchstring) pvsearch ON pv.VariantID = pvsearch.[KEY]

0 个答案:

没有答案