Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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_Full Text Search - Fatal编程技术网

Sql server 跨多个表使用全文搜索搜索记录

Sql server 跨多个表使用全文搜索搜索记录,sql-server,full-text-search,Sql Server,Full Text Search,上面的查询用于在两个表中搜索记录(使用排名) 第一个查询:只有搜索文本位于两个表的两列中的记录才会显示 第二次查询:仅搜索文本仅在表a的a列中的记录 第三个查询:仅搜索文本仅在表b的b列中的记录 我的问题是:如果我必须搜索4到5个表格,工会的数量将疯狂增加。这将是太复杂和缓慢以及 那么,有没有其他方法可以减少这种结合呢? 我尝试了视图,但无法对其进行全文索引。只需使用完全联接即可 SELECT A.a, B.b, akt.[Rank] + bkt.[Rank] /2 AS [Rank] FRO

上面的查询用于在两个表中搜索记录(使用排名)

第一个查询:只有搜索文本位于两个表的两列中的记录才会显示

第二次查询:仅搜索文本仅在表a的a列中的记录

第三个查询:仅搜索文本仅在表b的b列中的记录

我的问题是:如果我必须搜索4到5个表格,工会的数量将疯狂增加。这将是太复杂和缓慢以及

那么,有没有其他方法可以减少这种结合呢? 我尝试了视图,但无法对其进行全文索引。

只需使用完全联接即可

SELECT A.a, B.b, akt.[Rank] + bkt.[Rank] /2  AS [Rank]
FROM B b
INNER JOIN Publication a ON a.Id = b.Id
INNER JOIN FREETEXTTABLE(A, a, 'search text') akt ON a.Id = akt.[Key]
INNER JOIN FREETEXTTABLE(B, b, 'search text') bkt ON b.Id = bkt.[Key] 
ORDER BY [Rank] DESC

UNION
SELECT A.a, null as B.b, akt.[Rank] as [Rank]
FROM A a
INNER JOIN FREETEXTTABLE(A, a, 'search text') akt ON a.Id = akt.[Key]

UNION
SELECT null as A.a, B.b, bkt.[Rank] as [Rank]
FROM B b
INNER JOIN FREETEXTTABLE(A, a, 'search text') akt ON a.Id = akt.[Key]
检查

以上是使用UNION

下面是你建议的

选择b.FK_Publication_ID,b.PageNumber作为PageNumber,b.SearchText作为SearchText,a.Title作为Title作为ContentType

SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, a.Title as Title , 
TitleSearch.[Rank] + PubSearch.[Rank] * 10000
  AS [Rank]
FROM PublicationSearch 
INNER JOIN Publication a ON b.FK_Publication_Id = a.Id
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key] 
INNER JOIN FREETEXTTABLE(Publication, Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key] 
WHERE b.FK_ContentType_Id IN (SELECT * FROM UF_CSVToTable(@Options))

UNION 


SELECT  a.Id, null as PageNumber, null as Searchtext, a.Title as Title, TitleSearch.[Rank] * 100  AS [Rank]
FROM Publication a
INNER JOIN FREETEXTTABLE(Publication,Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key]


UNION

SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, null as Title, 
PubSearch.[Rank] 
  AS [Rank] 
FROM PublicationSearch b
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key] 

ORDER BY [Rank] DESC
这是确切的剧本。使用完全联接,我从表中获取记录,并仅从PublicationSearch表中获取记录,而不仅仅从Publication表中获取记录

此外,在两个表中找到的记录应排名更高,然后是仅发布表中的记录,然后是PublicationSerach表中的记录


谢谢..

谢谢Rain,这是可行的,但排名只针对两列中的记录,对于其他记录,排名=NULLYes,排名将为null。这就是为什么我告诉你用大小写来计算等级。请显示您正在使用的确切脚本,然后我将进行检查。
SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, a.Title as Title , 
TitleSearch.[Rank] + PubSearch.[Rank] * 10000
  AS [Rank]
FROM PublicationSearch 
INNER JOIN Publication a ON b.FK_Publication_Id = a.Id
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key] 
INNER JOIN FREETEXTTABLE(Publication, Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key] 
WHERE b.FK_ContentType_Id IN (SELECT * FROM UF_CSVToTable(@Options))

UNION 


SELECT  a.Id, null as PageNumber, null as Searchtext, a.Title as Title, TitleSearch.[Rank] * 100  AS [Rank]
FROM Publication a
INNER JOIN FREETEXTTABLE(Publication,Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key]


UNION

SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, null as Title, 
PubSearch.[Rank] 
  AS [Rank] 
FROM PublicationSearch b
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key] 

ORDER BY [Rank] DESC
TitleSearch.[Rank] * 100  (Ranking, dont know how to do it here)
  AS [Rank]
FROM PublicationSearch b
INNER JOIN Publication a ON b.FK_Publication_Id = a.Id
JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext")PubSearch ON b.Id = PubSearch.[Key] 
FULL JOIN FREETEXTTABLE(Publication, Title, "searchtext")TitleSearch ON a.Id = TitleSearch.[Key] 

order by [RANK] desc