I have set up full-text indexing in my database along with a CONTAINSTABLE
so users can search on the website against product SKUs & product names. I have set up a customization on the search, to where it strips the hyphen (-) out of a users search and in the database column when it grabs values. I have run into an issue on the search where searching '10-10' results in a broken page, with the error listing as so :
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)
The search works great otherwise, and I know that the hypen shouldn't be an issue, because if I search 'tw5-c' I get a few results returned. Is it possible that too many results are being returned and the connection is timing-out?
Here is the SQL CONTAINSTABLE statement:
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]