{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/dhamma-gift/json-schema/dhamma-gift-search-response-schema.json",
  "title": "SearchResponse",
  "x-generated": "2026-11-05",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/dhamma-gift-openapi.json#/components/schemas/SearchResponse",
  "type": "object",
  "properties": {
    "metadata": {
      "$ref": "#/$defs/SearchMetadata"
    },
    "data": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/SuttaResult"
      }
    },
    "wordReport": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/WordReportEntry"
      }
    },
    "variantSegments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/VariantSegment"
      }
    }
  },
  "$defs": {
    "SearchMetadata": {
      "type": "object",
      "properties": {
        "query": {
          "type": "string"
        },
        "scope": {
          "type": "string"
        },
        "langs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "lb": {
          "type": "integer"
        },
        "la": {
          "type": "integer"
        },
        "exactMatch": {
          "type": "boolean"
        },
        "totalFiles": {
          "type": "integer",
          "description": "Число найденных сутт"
        },
        "totalMatches": {
          "type": "integer",
          "description": "Суммарное число совпадений"
        },
        "hasVariantMatch": {
          "type": "boolean",
          "description": "Есть ли варианты чтения для этого слова где-либо в корпусе (не только в текущем scope)"
        },
        "partial": {
          "type": "boolean",
          "description": "true — это ответ ?fast=1, root-текст/переводы для части сегментов ещё не подгружены (см. /search/enrich)"
        },
        "tooShort": {
          "type": "boolean",
          "description": "true — keyword короче минимальной длины (3 символа), поиск не выполнялся"
        }
      }
    },
    "Segment": {
      "type": "object",
      "properties": {
        "segment": {
          "type": "string"
        },
        "root_text": {
          "type": "string",
          "description": "Пали, root-чтение"
        },
        "variant": {
          "type": "string",
          "description": "Пали, вариантное чтение (если есть)"
        },
        "translations": {
          "type": "object",
          "description": "Ключ вида \"ru_khantibalo\", \"en_sujato\" -> текст перевода",
          "additionalProperties": {
            "type": "string"
          }
        },
        "html": {
          "type": "string"
        },
        "lb_context": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "la_context": {
          "type": "array",
          "items": {
            "type": "object"
          }
        }
      }
    },
    "SuttaResult": {
      "type": "object",
      "properties": {
        "sutta_id": {
          "type": "string"
        },
        "category": {
          "type": "string",
          "enum": [
            "dhamma",
            "khudakka",
            "vinaya",
            "abhi",
            "other"
          ]
        },
        "dir_path": {
          "type": "string"
        },
        "titles": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "mr": {
          "type": "integer",
          "description": "Ранг версии/релевантности (mtph из textinfo)"
        },
        "count": {
          "type": "integer",
          "description": "Число совпадений в этой сутте"
        },
        "unique_words": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "segments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Segment"
          }
        }
      }
    },
    "VariantSegment": {
      "type": "object",
      "description": "Сегмент, где keyword встречается в вариантном (не root) чтении — текст берётся из variant-файла как есть, включая редакторскую нотацию разночтений (\"→\", \"(mr)\", \"(?)\").",
      "properties": {
        "sutta_id": {
          "type": "string"
        },
        "segment": {
          "type": "string"
        },
        "text": {
          "type": "string"
        }
      }
    },
    "WordReportEntry": {
      "type": "object",
      "properties": {
        "word": {
          "type": "string"
        },
        "textCount": {
          "type": "integer"
        },
        "matchCount": {
          "type": "integer"
        },
        "links": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "sutta_id": {
                "type": "string"
              },
              "segment": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}