{
  "searchRecords": {
    "get": {
      "operationId": "searchRecords",
      "tags": ["Records"],
      "summary": "Search readable records",
      "description": "Searches current records linked to the calling connection. All words must match. The last word also matches a prefix. Each page uses current permissions, and edits can move records between pages.",
      "parameters": [
        {"name": "q", "in": "query", "required": true, "schema": {"type": "string", "minLength": 1, "maxLength": 200}},
        {
          "name": "kind",
          "in": "query",
          "schema": {
            "type": "string",
            "enum": ["place", "event", "recipe", "guide", "workout", "note", "link", "media", "product"]
          }
        },
        {"name": "limit", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 100, "default": 100}},
        {
          "name": "cursor",
          "in": "query",
          "description": "Use next_cursor from the previous page with the same query, kind and deep flag.",
          "schema": {"type": "string"}
        },
        {
          "name": "deep",
          "in": "query",
          "description": "Search retained source captions, transcripts and page text. Requires a first-party Pigeon session and Pro.",
          "schema": {"type": "boolean", "default": false}
        }
      ],
      "responses": {
        "200": {
          "description": "A page of matching records. A null cursor indicates the final page.",
          "headers": {
            "request-id": {"$ref": "../components/headers.yaml#/RequestId"},
            "Cache-Control": {"$ref": "../components/headers.yaml#/CacheControl"}
          },
          "content": {"application/json": {"schema": {"$ref": "#/SearchPage"}}}
        },
        "400": {
          "description": "Invalid search input or a cursor that no longer matches the request.",
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": ["invalid_request", "invalid_cursor"]
        },
        "401": {"$ref": "../components/responses.yaml#/Hub401"},
        "402": {
          "description": "Deep search requires Pro.",
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": ["pro_required"]
        },
        "403": {
          "description": "The connection, account or requested search mode is unavailable.",
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": [
            "connection_disconnected",
            "connection_required",
            "connection_paused",

            "sapphire_account_required",

            "scope_denied"
          ]
        },
        "409": {
          "description": "Pigeon data deletion is in progress.",
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": ["pigeon_data_deleting"]
        },
        "410": {"$ref": "../components/responses.yaml#/Hub410"},
        "422": {"$ref": "../components/responses.yaml#/Hub422"},
        "429": {
          "description": "The connection's read rate limit was reached.",
          "headers": {"Retry-After": {"$ref": "../components/headers.yaml#/RetryAfter"}},
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": ["rate_limited"]
        },
        "503": {
          "description": "Search is temporarily unavailable.",
          "content": {"application/problem+json": {"schema": {"$ref": "../components/schemas.yaml#/Problem"}}},
          "x-error-codes": ["hub_not_configured", "hub_not_ready", "internal_error"]
        }
      }
    }
  },
  "SearchPage": {
    "type": "object",
    "required": ["results", "next_cursor"],
    "properties": {
      "results": {
        "type": "array",
        "items": {
          "type": "object",
          "required": ["id", "kind", "title", "snippet", "updated_at"],
          "properties": {
            "id": {"type": "string", "format": "uuid"},
            "kind": {"type": "string"},
            "title": {"type": ["string", "null"]},
            "snippet": {
              "type": ["string", "null"],
              "maxLength": 160,
              "description": "Plain text beginning at the first matching word."
            },
            "match_reason": {
              "type": "object",
              "description": "Included on deep hits with a matched text term.",
              "required": ["field", "excerpt"],
              "properties": {
                "field": {"enum": ["title", "tags", "body", "source", "creator", "caption", "transcript", "page_text"]},
                "excerpt": {"type": "string", "maxLength": 160, "description": "Same plain text as snippet."}
              }
            },
            "updated_at": {"type": "string", "format": "date-time"}
          }
        }
      },
      "next_cursor": {"type": ["string", "null"]}
    }
  }
}
