Cloud Search チュートリアルのこのページでは、データソースの設定方法について説明します。 コンテンツコネクタもあります このチュートリアルの初めから、 Cloud Search スタートガイドのチュートリアル
コネクタを構築する
作業ディレクトリを cloud-search-samples/end-to-end/connector
に変更します。
次のコマンドを実行します。
mvn package -DskipTests
このコマンドにより、アプリケーションのビルドに必要な依存関係が コードがコンパイルされます。
サービス アカウントの認証情報を作成する
コネクタには、Cloud Search を呼び出すためのサービス アカウントの認証情報が必要です。 API認証情報を作成するには:
- 戻る Google Cloud コンソール。
- 左側のナビゲーションで [認証情報] をクリックします。「認証情報」ページが表示されます。
- [+ 認証情報を作成] プルダウン リストをクリックして、 サービス アカウント。[サービス アカウントの作成]ページが表示されます。
- [サービス アカウント名] フィールドに「tutorial」と入力します。
- サービス アカウント ID の値(サービス アカウント名の直後)をメモします。 この値は後で使用されます。
- [作成] をクリックします。[サービス アカウントの権限(オプション)]ダイアログが表示されます。
- [続行] をクリックします[ユーザーにこのサービス アカウントへのアクセスを許可] (省略可)"ダイアログが表示されます。
- [完了] をクリックします。「認証情報」画面が表示されます。
- [サービス アカウント] で、サービス アカウントのメールアドレスをクリックします。「サービス アカウントの詳細」。
- [鍵] で [鍵を追加] プルダウン リストをクリックし、 新しい鍵を作成します。[Create private key]ダイアログが表示されます。
- [作成] をクリックします。
- (省略可)[Do you want to allow download on on console.cloud.google.com?”ダイアログが表示されたら、[許可] をクリックします。
- 秘密鍵ファイルがパソコンに保存されます。場所をメモする 表示されます。このファイルを使用してコンテンツ コネクタを設定し、 Google Cloud Search API を呼び出すときに自身を認証できます。
サードパーティ サポートを初期化する
他の Cloud Search API を呼び出すには、その前にサードパーティ サポートするようになりました
Cloud Search に対するサードパーティのサポートを初期化するには:
Cloud Search Platform プロジェクトには、サービス アカウントの認証情報が含まれています。 ただし、サードパーティのサポートを初期化するために、 認証情報を取得できます。ウェブ アプリケーションを作成する手順については、 詳しくは、このモジュールの 認証情報を作成します。 この手順を完了すると、クライアント ID とクライアント シークレット ファイルが作成されます。
使用 Google の OAuth 2 プレイグラウンド アクセス トークンを取得します。
- 設定をクリックし、[User your own auth credentials] をオンにします。
- ステップ 1 のクライアント ID とクライアント シークレットを入力します。
- [閉じる] をクリックします。
- [Scopes] フィールドに「
https://www.googleapis.com/auth/cloud_search.settings
」と入力します。 [承認] をクリックします。OAuth 2 Playground から認証コードが返されます。 - [Exchange authorization code for token] をクリックします。トークンが返されます。
サードパーティによる Cloud Search のサポートを初期化するには、次の curl を使用します。 使用できます。
[YOUR_ACCESS_TOKEN]
は、モジュールで取得したトークンに置き換えてください。 ステップ 2:curl --request POST \ 'https://cloudsearch.googleapis.com/v1:initializeCustomer' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{}' \ --compressed
成功した場合、レスポンスの本文には
operation
。次に例を示します。{ name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY" }
問題が解決しない場合は、Cloud Search サポートにお問い合わせください。
operations.get を使用して、 初期化されます。
curl \ 'https://cloudsearch.googleapis.com/v1/operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY?key= [YOUR_API_KEY]' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --header 'Accept: application/json' \ --compressed
サードパーティの初期化が完了すると、 フィールド
done
をtrue
に設定。例:{ name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY" done: true }
データソースを作成する
次に、管理コンソールでデータソースを作成します。データソース は、コネクタを使用してコンテンツをインデックス登録するための名前空間を提供します。
- Google 管理コンソールを開きます。
- アプリアイコンをクリックします。「Apps Administration」ページが表示されます。
- [Google Workspace] をクリックします。「Apps Google Workspace Administration」ページが表示されます。
- 下にスクロールして [Cloud Search] をクリックします。[Google Workspace の設定]ページ 表示されます。
- [第三者データソース] をクリックします。「データソース」ページが表示されます。
- 黄色の丸い [+] をクリックします。[新しいデータソースを追加]ダイアログが表示されます。
- [表示名] フィールドに「tutorial」と入力します。
- [サービス アカウントのメールアドレス] フィールドに、メールアドレスを入力します。 前のセクションで作成したサービス アカウント。もし メール アドレスを確認し、サービス アカウントの サービス アカウント できます。
- [追加] をクリックします。[正常に作成されたデータソース]ダイアログが表示されます。
- *[OK] をクリックします。新しく作成したデータソースの [ソース ID] をメモします。「 ソース ID はコンテンツ コネクタの設定に使用されます。
GitHub API 用の個人用アクセス トークンを生成する
コネクタを使用するには、GitHub API への認証済みアクセスが必要です。 十分な割り当てが必要ですわかりやすくするため、コネクタでは個人用の アクセス トークンを使用します。個人用トークンを使用すると、 OAuth と同様に限定的な権限セットを持つユーザーに作成されます。
- GitHub にログインします。
- 右上のプロフィール写真をクリックします。プルダウン メニューが表示されます。
- [設定] をクリックします。
- [デベロッパー向けの設定] をクリックします。
- [Personal access token] をクリックします。
- [Generate Personal access token] をクリックします。
- [Note] フィールドに「Cloud Searchtutorial」と入力します。
- public_repo スコープを確認します。
- [Generate token] をクリックします。
- 生成されたトークンをメモします。コネクタはこれを使用して、GitHub API を呼び出します。 インデックス登録を実行するための API 割り当てを提供します。
コネクタを構成する
認証情報とデータソースを作成したら、コネクタを更新する これらの値を含むように設定します。
- コマンドラインから、
cloud-search-samples/end-to-end/connector/
。 - テキスト エディタで
sample-config.properties
ファイルを開きます。 api.serviceAccountPrivateKeyFile
パラメータをアプリケーションのファイルパスに設定します。 サービス認証情報が必要です。api.sourceId
パラメータをデータソースの ID に設定します。 必要があります。github.user
パラメータを GitHub ユーザー名に設定します。github.token
パラメータを以前に作成したアクセス トークンに設定します。- ファイルを保存します。
スキーマを更新する
コネクタは、構造化コンテンツと非構造化コンテンツの両方をインデックスに登録します。インデックス登録前 データソースのスキーマを更新する必要があります。次のコマンドを実行します。 スキーマを更新します。
mvn exec:java -Dexec.mainClass=com.google.cloudsearch.tutorial.SchemaTool \
-Dexec.args="-Dconfig=sample-config.properties"
コネクタを実行する
コネクタを実行してインデックス登録を開始するには、次のコマンドを実行します。
mvn exec:java -Dexec.mainClass=com.google.cloudsearch.tutorial.GithubConnector \
-Dexec.args="-Dconfig=sample-config.properties"
コネクタのデフォルト構成では、単一のリポジトリがインデックスに登録される
googleworkspace
組織内のユーザー。リポジトリのインデックス登録には 1 分ほどかかります。
最初のインデックス登録の後、コネクタは
Cloud Search インデックスに反映する必要があります。
コードの確認
以降のセクションでは、コネクタの構築方法について説明します。
アプリケーションの起動
コネクタのエントリ ポイントは GithubConnector
クラスです。「
main
メソッドは、SDK の IndexingApplication
をインスタンス化します。
起動します。
ListingConnector
トラバーサル戦略を実装します
Cloud Search キューを活用
を使用してインデックス内のアイテムの状態を追跡できます。GithubRepository
に委任します。
によって実装され、GitHub のコンテンツにアクセスするために使用されます。
GitHub リポジトリの走査
フル走査中は、getIds()
メソッドは、インデックス登録が必要なアイテムをキューに push するために呼び出されます。
コネクタは、複数のリポジトリまたは組織のインデックスを作成できます。デフォルトの
一度に 1 つの GitHub リポジトリが走査されますチェックポイント
トラバーサルの結果とともに返されます。
後続の getIds()
の呼び出しでインデックスに登録されるようにします。エラーの場合
が発生すると、インデックス作成は開始せずに現在のリポジトリで再開されます。
あります。
collectRepositoryItems()
メソッドは、単一の
GitHub リポジトリ。このメソッドは、ApiOperations
のコレクションを返します。
キューに push するアイテムを表します。アイテムは
アイテムの現在の状態を表すハッシュ値が含まれています。
ハッシュ値は、GitHub の以降の走査で使用されます。 できます。この値は、コンテンツが 変更された内容がある。コネクタをやみくもに使用 すべてのアイテムをキューに入れます。アイテムが新しい場合やハッシュ値が変更された場合、 キューに入れられます。それ以外の場合、アイテムは未修正とみなされます。
キューを処理しています
フル走査が完了すると、コネクタは
キューに格納できます。getDoc()
メソッドはキューから pull されたアイテムごとに呼び出されます。このメソッドは、
GitHub からアイテムを取得し、適切な表現に変換
指定します。
コネクタは、随時変更される可能性のあるライブデータに対して実行されているため、
getDoc()
は、キュー内のアイテムがまだ有効であることも確認します。
インデックスから存在しなくなったアイテムを削除します。
コネクタは、GitHub オブジェクトごとに、対応する
indexItem()
メソッドは、アイテムのアイテム表現の作成を処理します。
Cloud Search。たとえば、コンテンツ アイテムの表現を作成するには、次のようにします。
次に、検索インターフェースをデプロイします。