# dev.knotless.searchCode

> Searches the default branches of the public repositories an appview indexes, in Zoekt's query language: words and quoted text as substrings, ignoring case unless the query holds a capital, a regular expression between slashes, and filters such as file:, lang: and case:yes. No authentication needed. Repositories taken down are left out. An appview that searches no code answers 501.

- Kind: query
- Authority: knotless.dev
- Lexicon: 1
- Published by [lexicons.knotless.dev](https://lexicon.garden/identity/did:plc:yqsg7znbbhfmj3a2nrpnaerk), the NSID's authority

## Links

- [Documentation](https://lexicon.garden/lexicon/did:plc:yqsg7znbbhfmj3a2nrpnaerk/dev.knotless.searchCode)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:yqsg7znbbhfmj3a2nrpnaerk/dev.knotless.searchCode/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:yqsg7znbbhfmj3a2nrpnaerk/dev.knotless.searchCode/analytics)

## Query (`dev.knotless.searchCode`)

Type: query · GET

### Parameters (query string)

- `cursor` (string): How many files the pages before held. The pages go 200 files deep at most.
  - Constraints: maxLength: 32
- `limit` (integer): The most files to answer with.
  - Constraints: minimum: 1, maximum: 50, default: 20
- `q` (string, required): What to search for.
  - Constraints: maxLength: 1000
- `repo` (string · at-uri): Only this repository's dev.knotless.repo record, its authority a DID or a handle.

### Output (application/json)

- `cursor` (string): Absent on the last page, and once the pages are 200 files deep.
- `fileCount` (integer, required): How many files the query found in all, of which files are the best.
  - Constraints: minimum: 0
- `files` (array, required)
  - `items` (ref)
    - Reference: `#fileView`
- `languages` (array): The languages of the files found, counting those its lang: filters leave out, most files first: of the first 1000 files at most. The first page alone lists them.
  - `items` (ref)
    - Reference: `#languageCount`
- `matchCount` (integer, required): How many matches the query found in all.
  - Constraints: minimum: 0

## #chunk (`dev.knotless.searchCode#chunk`)

Type: object

Lines of a file holding matches, with a line on either side.

### Properties

- `content` (string, required): The lines, each after the first following a newline, with no newline at the end.
- `highlights` (string): What its highlighting paints over the content, encoded as dev.knotless.getFile's ranges are, the lines read alone. Absent for a language with no grammar.
- `ranges` (array, required)
  - `items` (ref)
    - Reference: `#range`
- `startLine` (integer, required): The first line's number, from 1.
  - Constraints: minimum: 1

## #fileView (`dev.knotless.searchCode#fileView`)

Type: object

A file the query found, with the lines around what it found there.

### Properties

- `chunks` (array, required): Runs of lines holding matches, in order. Empty when only the path matched.
  - `items` (ref)
    - Reference: `#chunk`
- `commit` (string): The commit of the default branch that was indexed, whose lines these are: a page of the file links there, as the branch may have moved since.
  - Constraints: maxLength: 64
- `language` (string): What it is written in, as Zoekt names it from its extension or contents.
  - Constraints: maxLength: 100
- `path` (string, required): The file's path in the repository's default branch.
  - Constraints: maxLength: 4096
- `repo` (ref, required)
  - Reference: `dev.knotless.listRepos#repoView`

## #languageCount (`dev.knotless.searchCode#languageCount`)

Type: object

A language files were found in, and how many.

### Properties

- `color` (string): Its color, as linguist has it. Absent for a language with none known here.
- `files` (integer, required)
  - Constraints: minimum: 1
- `name` (string, required): As Zoekt names it, and lang: takes it.

## #range (`dev.knotless.searchCode#range`)

Type: object

A match, or the part of one on one line.

### Properties

- `byteEnd` (integer, required): Where it ends, in UTF-8 bytes, exclusive.
  - Constraints: minimum: 0
- `byteStart` (integer, required): Where the match starts on the line, in its UTF-8 bytes.
  - Constraints: minimum: 0
- `line` (integer, required): The line's number, from 1.
  - Constraints: minimum: 1

## Schema

```json
{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "chunk": {
      "description": "Lines of a file holding matches, with a line on either side.",
      "properties": {
        "content": {
          "description": "The lines, each after the first following a newline, with no newline at the end.",
          "type": "string"
        },
        "highlights": {
          "description": "What its highlighting paints over the content, encoded as dev.knotless.getFile's ranges are, the lines read alone. Absent for a language with no grammar.",
          "type": "string"
        },
        "ranges": {
          "items": {
            "ref": "#range",
            "type": "ref"
          },
          "type": "array"
        },
        "startLine": {
          "description": "The first line's number, from 1.",
          "minimum": 1,
          "type": "integer"
        }
      },
      "required": [
        "startLine",
        "content",
        "ranges"
      ],
      "type": "object"
    },
    "fileView": {
      "description": "A file the query found, with the lines around what it found there.",
      "properties": {
        "chunks": {
          "description": "Runs of lines holding matches, in order. Empty when only the path matched.",
          "items": {
            "ref": "#chunk",
            "type": "ref"
          },
          "type": "array"
        },
        "commit": {
          "description": "The commit of the default branch that was indexed, whose lines these are: a page of the file links there, as the branch may have moved since.",
          "maxLength": 64,
          "type": "string"
        },
        "language": {
          "description": "What it is written in, as Zoekt names it from its extension or contents.",
          "maxLength": 100,
          "type": "string"
        },
        "path": {
          "description": "The file's path in the repository's default branch.",
          "maxLength": 4096,
          "type": "string"
        },
        "repo": {
          "ref": "dev.knotless.listRepos#repoView",
          "type": "ref"
        }
      },
      "required": [
        "repo",
        "path",
        "chunks"
      ],
      "type": "object"
    },
    "languageCount": {
      "description": "A language files were found in, and how many.",
      "properties": {
        "color": {
          "description": "Its color, as linguist has it. Absent for a language with none known here.",
          "type": "string"
        },
        "files": {
          "minimum": 1,
          "type": "integer"
        },
        "name": {
          "description": "As Zoekt names it, and lang: takes it.",
          "type": "string"
        }
      },
      "required": [
        "name",
        "files"
      ],
      "type": "object"
    },
    "main": {
      "description": "Searches the default branches of the public repositories an appview indexes, in Zoekt's query language: words and quoted text as substrings, ignoring case unless the query holds a capital, a regular expression between slashes, and filters such as file:, lang: and case:yes. No authentication needed. Repositories taken down are left out. An appview that searches no code answers 501.",
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "cursor": {
              "description": "Absent on the last page, and once the pages are 200 files deep.",
              "type": "string"
            },
            "fileCount": {
              "description": "How many files the query found in all, of which files are the best.",
              "minimum": 0,
              "type": "integer"
            },
            "files": {
              "items": {
                "ref": "#fileView",
                "type": "ref"
              },
              "type": "array"
            },
            "languages": {
              "description": "The languages of the files found, counting those its lang: filters leave out, most files first: of the first 1000 files at most. The first page alone lists them.",
              "items": {
                "ref": "#languageCount",
                "type": "ref"
              },
              "type": "array"
            },
            "matchCount": {
              "description": "How many matches the query found in all.",
              "minimum": 0,
              "type": "integer"
            }
          },
          "required": [
            "files",
            "fileCount",
            "matchCount"
          ],
          "type": "object"
        }
      },
      "parameters": {
        "properties": {
          "cursor": {
            "description": "How many files the pages before held. The pages go 200 files deep at most.",
            "maxLength": 32,
            "type": "string"
          },
          "limit": {
            "default": 20,
            "description": "The most files to answer with.",
            "maximum": 50,
            "minimum": 1,
            "type": "integer"
          },
          "q": {
            "description": "What to search for.",
            "maxLength": 1000,
            "type": "string"
          },
          "repo": {
            "description": "Only this repository's dev.knotless.repo record, its authority a DID or a handle.",
            "format": "at-uri",
            "type": "string"
          }
        },
        "required": [
          "q"
        ],
        "type": "params"
      },
      "type": "query"
    },
    "range": {
      "description": "A match, or the part of one on one line.",
      "properties": {
        "byteEnd": {
          "description": "Where it ends, in UTF-8 bytes, exclusive.",
          "minimum": 0,
          "type": "integer"
        },
        "byteStart": {
          "description": "Where the match starts on the line, in its UTF-8 bytes.",
          "minimum": 0,
          "type": "integer"
        },
        "line": {
          "description": "The line's number, from 1.",
          "minimum": 1,
          "type": "integer"
        }
      },
      "required": [
        "line",
        "byteStart",
        "byteEnd"
      ],
      "type": "object"
    }
  },
  "description": "Searches the code of the public repositories an appview indexes.",
  "id": "dev.knotless.searchCode",
  "lexicon": 1
}
```
