我正在SQL Server 2014上实施全文搜索。我在本教程的第4步中添加了dbo.Blocks
表dbo.Articles
http://www.mikesdotnetting.com/article/298/implementing-sql-server-full-text-search-in-an-asp-net-mvc-web-application-with-entity-framework
我为我的目的简化了搜索程序:
CREATE PROCEDURE Search
@SearchTerm varchar(8000),
@CurrentPage int = 1,
@PageSize int = 20
AS
BEGIN
DECLARE @NearPredicate varchar(8000),
@AndPredicate varchar(8000),
@TotalRecords int
SELECT
@NearPredicate = COALESCE(@NearPredicate + ' NEAR ', '') + items
FROM
dbo.Split(@SearchTerm, ' ')
LEFT JOIN
sys.fulltext_system_stopwords ON items = stopword
WHERE
stopword IS NULL
SET @AndPredicate = REPLACE(@NearPredicate, 'NEAR', 'AND')
SET @NearPredicate = '(' + @NearPredicate + ')'
SET @TotalRecords = (
SELECT
COUNT(*)
FROM
AbstractBuildBlocks
WHERE CONTAINS(*, @AndPredicate )
)
SELECT a.SiteId,
a.Content,
ct.Rank,
@TotalRecords AS TotalRecords
FROM
AbstractBuildBlocks a
INNER JOIN CONTAINSTABLE (Blocks, *, @NearPredicate ) AS ct ON a.Id = ct.[Key]
ORDER BY
ct.RANK DESC
OFFSET (@CurrentPage - 1) * @PageSize ROWS FETCH NEXT @PageSize ROWS only
END
我尝试在SQL Server Management Studio中测试它:按新查询,打印EXEC Search @SearchTerm="sample", @CurrentPage = 1
并点击!执行。
有两个问题:
小:SQL Server Management Studio在我的查询中强调Search
并说:
无法找到存储过程'搜索
Big:执行查询时服务器抛出错误:
第34行Msg 208,Level 16,State 1,Procedure Search,Line 34
无效的对象名称'块'。
:
FROM dbo.Split(@SearchTerm, ' ') /*line 34*/
我发现它很奇怪,因为我已经创建了数据库dbo.Blocks
,并且在Split
功能我甚至不使用此表。
不知道它是否重要,但dbo.Split
下划线为红色,消息:Invalid object name
,但尽管此过程已成功创建并存储。
最后我尝试用Blocks
替换dbo.Blocks
这里:
FROM
AbstractBuildBlocks a
INNER JOIN CONTAINSTABLE (Blocks, *, @NearPredicate ) AS ct ON a.Id = ct.[Key]
并重新编译程序 - 现在出错:
Msg 208,Level 16,State 1,Procedure Search,Line 34
无效的对象名称' dbo.Blocks'。 / 而不是块 /
更新我已使用此
SELECT '['+SCHEMA_NAME(schema_id)+'].['+name+']'
AS SchemaTable
FROM sys.tables
答案 0 :(得分:1)
您尝试将Blocks
对象用作表格,但它是您的全文目录的名称。如果查看CONTAINSTABLE
documentation,则第一个参数是已全文索引的表。第一个参数应该是dbo.Search
吗?