構造化データまたは非構造化データのカスタム検索をフィルタします。

構造化データ、またはメタデータを含む非構造化データを使用する検索アプリがある場合は、メタデータを使用して検索クエリをフィルタできます。このページでは、メタデータ フィールドを使用して、検索を特定の条件をもつドキュメントに制限する方法について説明します。

メタデータの例

4 つの PDF ファイル(document_1.pdfdocument_2.pdfdocument_3.pdfdocument_4.pdf)のメタデータの例を確認します。このメタデータは、PDF ファイルとともに Cloud Storage バケット内の JSON ファイルに格納されます。この例を参照しながらこのページを読んでください。

{"id": "1", "structData": {"title": "Policy on accepting corrected claims", "category": ["persona_A"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_1.pdf"}}
{"id": "2", "structData": {"title": "Claims documentation and reporting guidelines for commercial members", "category": ["persona_A", "persona_B"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_2.pdf"}}
{"id": "3", "structData": {"title": "Claims guidelines for bundled services and supplies for commercial members", "category": ["persona_B", "persona_C"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_3.pdf"}}
{"id": "4", "structData": {"title": "Advantage claims submission guidelines", "category": ["persona_A", "persona_C"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_4.pdf"}}

フィルタ式の構文

検索フィルタの定義に使用するフィルタ式の構文について理解しておきましょう。フィルタ式の構文は、次の Extended Backus-Naur form に要約できます。

  # A single expression or multiple expressions that are joined by "AND" or "OR".
  filter = expression, { " AND " | "OR", expression };
  # Expressions can be prefixed with "-" or "NOT" to express a negation.
  expression = [ "-" | "NOT " ],
    # A parenthetical expression.
    | "(", expression, ")"
    # A simple expression applying to a text field.
    # Function "ANY" returns true if the field exactly matches any of the literals.
    | text_field, ":", "ANY", "(", literal, { ",", literal }, ")"
    # A simple expression applying to any indexable field.
    # Preview: Function "EXISTS" returns true if the field is not NULL, empty, or containing the default value.
    | text_field, ":", "EXISTS"
    | numerical_field, ":", "EXISTS"
    # Function "CONTAINS" returns true if the field contains the tokens in any of the literals.
    # This is a partial match, not an exact match.
    | text_field, ":", "CONTAINS", "(", literal, ")"
    # Function "STARTS_WITH" returns true if the field begins with the same characters
    # as in any of the literals. The prefix matches up to 12 characters.
    | text_field, ":", "STARTS_WITH", "(", literal, ")"