{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://gmr.github.io/pglifecycle/schemata/text_search.json",
  "title": "Text Search",
  "description": "Defines all properties for text-search in a schema",
  "type": "object",
  "properties": {
    "schema": {
      "title": "Schema",
      "description": "The schema for the text search objects",
      "type": "string"
    },
    "configurations": {
      "title": "Text Search Configurations",
      "type": "array",
      "items": {
        "title": "Text Search Configuration",
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "description": "The name of the text search configuration to be created.",
            "type": "string"
          },
          "sql": {
            "title": "SQL Statement",
            "description": "User-provided SQL",
            "type": "string"
          },
          "parser": {
            "title": "Parser",
            "description": "The name of the text search parser to use",
            "type": "string"
          },
          "source": {
            "title": "Source Config",
            "description": "The name of an existing text search configuration to copy.",
            "type": "string"
          },
          "mappings": {
            "title": "Mappings",
            "description": "Each token type the configuration maps, with the dictionaries a token of that type is looked up in, in order (ALTER TEXT SEARCH CONFIGURATION ... ADD MAPPING).\n",
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            }
          },
          "comment": {
            "title": "Comment",
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": false,
        "oneOf": [
          {
            "required": [
              "sql"
            ],
            "not": {
              "required": [
                "parser",
                "source"
              ]
            }
          },
          {
            "required": [
              "parser"
            ],
            "not": {
              "required": [
                "source",
                "sql"
              ]
            }
          },
          {
            "required": [
              "source"
            ],
            "not": {
              "required": [
                "parser",
                "sql"
              ]
            }
          }
        ]
      }
    },
    "dictionaries": {
      "title": "Text Search Dictionary",
      "type": "array",
      "items": {
        "title": "Text Search Dictionary",
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "description": "The name of the text search dictionary to be created.",
            "type": "string"
          },
          "sql": {
            "title": "SQL Statement",
            "description": "User-provided SQL",
            "type": "string"
          },
          "template": {
            "title": "Template",
            "description": "The name of the text search template that will define the basic behavior of this dictionary.\n",
            "type": "string"
          },
          "options": {
            "title": "Options",
            "description": "Template specific options",
            "type": "object",
            "propertyNames": {
              "pattern": "^[A-Za-z0-9_]*$"
            }
          },
          "comment": {
            "title": "Comment",
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "oneOf": [
          {
            "required": [
              "sql"
            ],
            "not": {
              "required": [
                "template",
                "options"
              ]
            }
          },
          {
            "required": [
              "template"
            ],
            "not": {
              "required": [
                "sql"
              ]
            }
          }
        ],
        "additionalProperties": false
      }
    },
    "parsers": {
      "title": "Text Search Parsers",
      "type": "array",
      "items": {
        "title": "Text Search Parser",
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "description": "The name of the text search parser to be created.",
            "type": "string"
          },
          "sql": {
            "title": "SQL Statement",
            "description": "User-provided SQL",
            "type": "string"
          },
          "start_function": {
            "title": "Start Function",
            "description": "The name of the start function for the parser.",
            "type": "string"
          },
          "gettoken_function": {
            "title": "Get Token Function",
            "description": "The name of the get-next-token function for the parser.",
            "type": "string"
          },
          "end_function": {
            "title": "End Function",
            "description": "The name of the end function for the parser.",
            "type": "string"
          },
          "lextypes_function": {
            "title": "Lex-Types Function",
            "description": "The name of the lextypes function for the parser (a function that returns information about the set of token types it produces).\n",
            "type": "string"
          },
          "headline_function": {
            "title": "Headline Function",
            "description": "The name of the headline function for the parser (a function that summarizes a set of tokens).\n",
            "type": "string"
          },
          "comment": {
            "title": "Comment",
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "oneOf": [
          {
            "required": [
              "sql"
            ],
            "not": {
              "required": [
                "start_function",
                "gettoken_function",
                "end_function",
                "lextypes_function"
              ]
            }
          },
          {
            "required": [
              "start_function",
              "gettoken_function",
              "end_function",
              "lextypes_function"
            ],
            "not": {
              "required": [
                "sql"
              ]
            }
          }
        ],
        "additionalProperties": false
      }
    },
    "templates": {
      "title": "Text Search Templates",
      "type": "array",
      "items": {
        "title": "Text Search Template",
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "description": "The name of the text search template to be created.",
            "type": "string"
          },
          "sql": {
            "title": "SQL Statement",
            "description": "User-provided SQL",
            "type": "string"
          },
          "init_function": {
            "title": "Init Function",
            "description": "The name of the init function for the template.",
            "type": "string"
          },
          "lexize_function": {
            "title": "Lexize Function",
            "description": "The name of the lexize function for the template.",
            "type": "string"
          },
          "comment": {
            "title": "Comment",
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "oneOf": [
          {
            "required": [
              "sql"
            ],
            "not": {
              "required": [
                "lexize_function",
                "init_function"
              ]
            }
          },
          {
            "required": [
              "lexize_function"
            ],
            "not": {
              "required": [
                "sql"
              ]
            }
          }
        ],
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "schema"
  ]
}