This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.
こんにちは、 SQL Server サポート チームです。
本記事では SQL Server のフルテキスト検索機能を用いて Word や PDF ファイルから日本語を検索するための手順を紹介します。
SQL Server のフルテキスト検索の詳細については下記ページをご参照ください。
事前準備
1. 現在のフィルターに Word や PDF が対象になっているか確認します。
例えば、PDF を検索対象になっているかを確認するためには、下記クエリを実行します。
上記クエリの実行結果が0件だった場合は、PDF ファイルが検索対象になっていないことを意味します。その場合は、既定で有効になっていないワード ブレーカーおよびフィルターを検索対象に含まれるように下記コマンドを実行します。
PDF のフィルターが有効になっている場合は、以下のようにドライバーの情報が確認できます。
出力結果例
componenttype |
componentname |
clsid |
fullpath |
version |
manufacturer |
filter |
|
6C337B26-3E38-4F98-813B-FBA18BAB64F5 |
C:\Windows\system32\Windows.Data.Pdf.dll |
6.2.20348.1 |
Microsoft Corporation |
※ Word を検索対象になっているかを確認するためには、下記クエリを実行します。
2. ワード ブレーカーの設定を行います。
※ これからの作業では、レジストリの値を変更します。万が一の場合に元の値に戻せるように、本作業を実施する前にレジストリのバックアップを取得してください。
2.1 現在の日本語用の [WBreakerClass]レジストリの値をメモします。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15.<インスタンス名>\MSSearch\Language\jpn
2.2 ニュートラル用の [WBreakerClass]レジストリの値を上記で取得した日本語用の値で上書きします。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15.<インスタンス名>\MSSearch\Language\Neutral
2.3 レジストリを変更したら、SQL Server を再起動します。
※ 既にフルテキスト カタログの構築済みの場合は、ここでフルテキスト カタログの再構築を行います。
SQL Server Management Studio (SSMS) のオブジェクト エクスプローラーにて [対象のデータベース] > [ストレージ] > [フルテキスト カタログ] を順に展開し、対象のフルテキスト カタログを右クリック、[再構築] を選択します。
または、次の T-SQL を実行します。
ここまでで日本語をフルテキスト検索の対象にするための準備が完了しました。
※ 同様の設定に関して、以前 Windows Server 2008 R2 と SQL Server 2008 R2 で、Excel に関して同様の対処をご案内しておりましたが、バージョンによって GUID が異なるため、改めて本記事にて手順を案内させて頂きました。
日本語の検索方法
ここからは、実際にデータベースを作成して、日本語を検索するための手順を記載します。
1. 検証用のデータベース [Test] を作成します。
2. 検証用のテーブル [Table_1] を作成します。
3. フルテキスト カタログとフルテキスト インデックスを作成します。
4. 日本語を含めた PDF ファイルを用意し、検証用のデータを挿入します。
5. 日本語を用いてフルテキスト検索を実施します。
出力結果例
col1_id |
col2_data |
col3_ext |
F93B232-B838-4BC3-8A49-AA2AC58488 |
0x255044462D312E370D0A25B5B5B5.. |
|
Please refer to this blog to search Japanese words included in Word or PDF files using SQL Server's Full-Text Search feature.
Regarding Full-Text Search, please refer to the following page.
■ Prerequisites
1. First of all we should check if the Word or PDF are included in the current filter or not.
For example, if we want to search if the PDF filter is active or not, then we run this query.
If the result is 0 record, then PDF is not included in the filter. In that case, we need to run the following queries so that Full-Text Engine includes the word breakers and filters which are not included by default.
If PDF filters are active then, we can see the driver information like in the below table.
Result:
componenttype |
componentname |
clsid |
fullpath |
version |
manufacturer |
filter |
|
6C337B26-3E38-4F98-813B-FBA18BAB64F5 |
C:\Windows\system32\Windows.Data.Pdf.dll |
6.2.20348.1 |
Microsoft Corporation |
※ If we want to search if the Word filter is active or not, then we run this query.
2. Make sure to change the word breaker registry value.
※ We will make some changes to the registry. Please take a backup of the registry so that you can restore back if something goes wrong.
2.1 Take a memo of the current Japanese [WBreakerClass] registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15.<SQL Server Instance Name>\MSSearch\Language\jpn
2.2 Overwrite the current [WBreakerClass] registry for neutral with the value of Japanese [WBreakerClass] memoed at step 2.1.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15.<SQL Server Instance Name>\MSSearch\Language\Neutral
2.3 restart SQL Server service.
※ If the full-text catalog is already built, a rebuild is required. It can be done either by SQL Server Management Studio (SSMS) or by running the following T-SQL command.
Now, we are ready to search Japanese words from PDF using Full-Text Search.
■ Steps
Going forward, we will proceed to create a test database so that we can search Japanese words from a PDF file.
1. Create a [Test] database.
2. Create a table [Table_1].
3. Create full-text catalog and full-text index.
4. Create a sample pdf that contains Japanese characters with word [日本語].
5. Search for the Japanese word [日本語].
Result
col1_id |
col2_data |
col3_ext |
F93B232-B838-4BC3-8A49-AA2AC58488 |
0x255044462D312E370D0A25B5B5B5.. |
|