• <legend id='SShk0'><style id='SShk0'><dir id='SShk0'><q id='SShk0'></q></dir></style></legend>

      <bdo id='SShk0'></bdo><ul id='SShk0'></ul>
    <tfoot id='SShk0'></tfoot>

    <small id='SShk0'></small><noframes id='SShk0'>

    <i id='SShk0'><tr id='SShk0'><dt id='SShk0'><q id='SShk0'><span id='SShk0'><b id='SShk0'><form id='SShk0'><ins id='SShk0'></ins><ul id='SShk0'></ul><sub id='SShk0'></sub></form><legend id='SShk0'></legend><bdo id='SShk0'><pre id='SShk0'><center id='SShk0'></center></pre></bdo></b><th id='SShk0'></th></span></q></dt></tr></i><div id='SShk0'><tfoot id='SShk0'></tfoot><dl id='SShk0'><fieldset id='SShk0'></fieldset></dl></div>

      1. 在 SQL Server 2008 中跨多个表、列使用全文搜索

        Using Full-Text Search in SQL Server 2008 across multiple tables, columns(在 SQL Server 2008 中跨多个表、列使用全文搜索)

            <bdo id='gh6sN'></bdo><ul id='gh6sN'></ul>

              <tfoot id='gh6sN'></tfoot>

              <small id='gh6sN'></small><noframes id='gh6sN'>

            1. <legend id='gh6sN'><style id='gh6sN'><dir id='gh6sN'><q id='gh6sN'></q></dir></style></legend>

              • <i id='gh6sN'><tr id='gh6sN'><dt id='gh6sN'><q id='gh6sN'><span id='gh6sN'><b id='gh6sN'><form id='gh6sN'><ins id='gh6sN'></ins><ul id='gh6sN'></ul><sub id='gh6sN'></sub></form><legend id='gh6sN'></legend><bdo id='gh6sN'><pre id='gh6sN'><center id='gh6sN'></center></pre></bdo></b><th id='gh6sN'></th></span></q></dt></tr></i><div id='gh6sN'><tfoot id='gh6sN'></tfoot><dl id='gh6sN'><fieldset id='gh6sN'></fieldset></dl></div>

                  <tbody id='gh6sN'></tbody>
                • 本文介绍了在 SQL Server 2008 中跨多个表、列使用全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要使用全文搜索从我的数据库中的两个表中搜索多个列.有问题的两个表具有全文索引的相关列.

                  我选择全文搜索的原因:1. 能够轻松搜索重音词 (cafè)2. 能够根据词的接近度等进行排名.3. 你是说XXX吗?"功能

                  这是一个虚拟表结构,用于说明挑战:

                  <前>桌书书号名称(全文索引)注释(全文索引)桌架货架编号书号Table ShelfAuthor作者ID货架编号表格作者作者ID名称(全文索引)

                  我需要搜索书名、书注和作者姓名.

                  我知道有两种方法可以做到这一点:

                  1. 使用全文索引视图:这本来是我的首选方法,但我不能这样做,因为要对视图进行全文索引,它需要是模式绑定的,没有任何外部连接,有一个唯一的索引.我需要获取数据的视图不满足这些约束(它包含我需要从中获取数据的许多其他连接表).

                  2. 在存储过程中使用连接:这种方法的问题是我需要按等级对结果进行排序.如果我要跨表进行多个连接,默认情况下 SQL Server 不会跨多个字段进行搜索.我可以在两个链接表上组合两个单独的 CONTAINS 查询,但我不知道从两个搜索查询中提取组合排名的方法.例如,如果我搜索Arthur",则应考虑 Book 查询和 Author 查询的结果并相应地加权.

                  解决方案

                  使用 FREETEXTTABLE,您只需要设计一些算法来计算每个连接表结果的合并排名.下面的示例将结果偏向于图书表中的命中.

                  SELECT b.Name, a.Name, bkt.[Rank] + akt.[Rank]/2 AS [Rank]从书 bINNER JOIN 作者 a ON b.AuthorID = a.AuthorIDINNER JOIN FREETEXTTABLE(Book, Name, @criteria) bkt ON b.ContentID = bkt.[Key]LEFT JOIN FREETEXTTABLE(Author, Name, @criteria) akt ON a.AuthorID = akt.[Key]ORDER BY [Rank] DESC

                  请注意,我简化了此示例的架构.

                  I need to search across multiple columns from two tables in my database using Full-Text Search. The two tables in question have the relevant columns full-text indexed.

                  The reason I'm opting for Full-text search: 1. To be able to search accented words easily (cafè) 2. To be able to rank according to word proximity, etc. 3. "Did you mean XXX?" functionality

                  Here is a dummy table structure, to illustrate the challenge:

                  Table Book
                  BookID
                  Name (Full-text indexed)
                  Notes (Full-text indexed)
                  
                  Table Shelf
                  ShelfID
                  BookID
                  
                  Table ShelfAuthor
                  AuthorID
                  ShelfID
                  
                  Table Author
                  AuthorID
                  Name (Full-text indexed)
                  

                  I need to search across Book Name, Book Notes and Author Name.

                  I know of two ways to accomplish this:

                  1. Using a Full-text Indexed View: This would have been my preferred method, but I can't do this because for a view to be full-text indexed, it needs to be schemabound, not have any outer joins, have a unique index. The view I will need to get my data does not satisfy these constraints (it contains many other joined tables I need to get data from).

                  2. Using joins in a stored procedure: The problem with this approach is that I need to have the results sorted by rank. If I am making multiple joins across the tables, SQL Server won't search across multiple fields by default. I can combine two individual CONTAINS queries on the two linked tables, but I don't know of a way to extract the combined rank from the two search queries. For example, if I search for 'Arthur', the results of both the Book query and the Author query should be taken into account and weighted accordingly.

                  解决方案

                  Using FREETEXTTABLE, you just need to design some algorithm to calculate the merged rank on each joined table result. The example below skews the result towards hits from the book table.

                  SELECT b.Name, a.Name, bkt.[Rank] + akt.[Rank]/2 AS [Rank]
                  FROM Book b
                  INNER JOIN Author a ON b.AuthorID = a.AuthorID
                  INNER JOIN FREETEXTTABLE(Book, Name, @criteria) bkt ON b.ContentID = bkt.[Key] 
                  LEFT JOIN FREETEXTTABLE(Author, Name, @criteria) akt ON a.AuthorID = akt.[Key]
                  ORDER BY [Rank] DESC
                  

                  Note that I simplified your schema for this example.

                  这篇关于在 SQL Server 2008 中跨多个表、列使用全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)

                      <tbody id='NaWDy'></tbody>
                    <legend id='NaWDy'><style id='NaWDy'><dir id='NaWDy'><q id='NaWDy'></q></dir></style></legend>

                    <small id='NaWDy'></small><noframes id='NaWDy'>

                    • <tfoot id='NaWDy'></tfoot>

                          <i id='NaWDy'><tr id='NaWDy'><dt id='NaWDy'><q id='NaWDy'><span id='NaWDy'><b id='NaWDy'><form id='NaWDy'><ins id='NaWDy'></ins><ul id='NaWDy'></ul><sub id='NaWDy'></sub></form><legend id='NaWDy'></legend><bdo id='NaWDy'><pre id='NaWDy'><center id='NaWDy'></center></pre></bdo></b><th id='NaWDy'></th></span></q></dt></tr></i><div id='NaWDy'><tfoot id='NaWDy'></tfoot><dl id='NaWDy'><fieldset id='NaWDy'></fieldset></dl></div>
                          • <bdo id='NaWDy'></bdo><ul id='NaWDy'></ul>