Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server sql server全文搜索排名_Sql Server_Full Text Search - Fatal编程技术网

Sql server sql server全文搜索排名

Sql server sql server全文搜索排名,sql-server,full-text-search,Sql Server,Full Text Search,我不熟悉全文搜索功能。所以我需要一些帮助 问题是是否可以在ms sql server 2008 r2的全文搜索中设置自定义排名? 我对自定义排名的理解: i、 我们把书储存在数据库里。如果在Book1的book name和Book2的description中满足搜索条件,并且名称优先于description,则Book1应显示为第一条记录 提前谢谢 是的,您可以自己滚动,但不能保证大规模性能,因此请使用真实数据进行测试。其思想是单独查询字段,添加您自己的自定义排名,并合并结果 create t

我不熟悉全文搜索功能。所以我需要一些帮助

问题是是否可以在ms sql server 2008 r2的全文搜索中设置自定义排名? 我对自定义排名的理解: i、 我们把书储存在数据库里。如果在Book1的book name和Book2的description中满足搜索条件,并且名称优先于description,则Book1应显示为第一条记录


提前谢谢

是的,您可以自己滚动,但不能保证大规模性能,因此请使用真实数据进行测试。其思想是单独查询字段,添加您自己的自定义排名,并合并结果

 create table DoNotBlindlyRunMe.books 
 (
 id int not null identity primary key,
 Title varchar(100) not null,
 Author varchar(100) not null,
 [Description] varchar(500) not null
 )
 go
 CREATE FULLTEXT CATALOG [ft_books] WITH ACCENT_SENSITIVITY = ON
 GO
 --You need to edit this to match your PK index name!
 CREATE FULLTEXT INDEX ON [dbo].[books] KEY INDEX [PK__books__3213E83F3D5E1FD2] ON ([ft_books]) WITH (CHANGE_TRACKING AUTO)
 GO
 ALTER FULLTEXT INDEX ON [dbo].[books] ADD ([Author] LANGUAGE [English])
 GO
 ALTER FULLTEXT INDEX ON [dbo].[books] ADD ([Description] LANGUAGE [English])
 GO
 ALTER FULLTEXT INDEX ON [dbo].[books] ADD ([Title] LANGUAGE [English])
 GO
 ALTER FULLTEXT INDEX ON [dbo].[books] ENABLE
 GO

 insert into books (title, author, description)
 values ('The Cat in the Hat',     'Dr. Suess',     'An epic tale of a cat who teaches some valuable lessons.'),
 ('The Little Engine that Could',     'Watty Piper','A small train goes over a mountain.'),
 ('Favorite Nursery Rhymes by Mother Goose', 'Cat Stevens',     'Fairy tales from mother good, including peter piper.')

 --Rank Title highest, then Author, then description
 select [key], min([RANK]) [RANK] from (
      select [key], 100000000+ [RANK] RANK from containstable([books], [Title] , 'cat') union all
      select [key], 200000000+ [RANK] from containstable([books], [Author] , 'cat') union all
      select [key], 300000000+ [RANK] from containstable([books], [Description] , 'cat')
      ) ranked_containstable  GROUP by [key] order by MIN( [RANK] )

 --Or as a TVF
 go
 CREATE FUNCTION  DoNotBlindlyRunMe.RankedBookSearch (@ftQuery nvarchar(500))
 returns table return
 (
 select [key], min([RANK]) [RANK] from (
      select [key], 100000000+ [RANK] RANK from containstable([books], [Title] , @ftQuery) union all
      select [key], 200000000+ [RANK] from containstable([books], [Author] , @ftQuery) union all
      select [key], 300000000+ [RANK] from containstable([books], [Description] , @ftQuery)
      ) ranked_containstable  GROUP by [key]
 )
 go

 select * from dbo.RankedBookSearch(N'cat or stevens or piper')

你期望得到什么答案?我可以说“是”,但我担心你可能会感到沮丧。。。到目前为止你做了什么?你到底被困在哪里?我只是在调查可能的解决办法。是的,你的回答让我很惊讶,因为我还没有找到关于如何调整sql server进行自定义排名的信息或教程。如果你知道这些教程,请分享)我今天在搜索时发现了这个问题。。。我发现这个链接对任何有同样问题的人都有帮助。