# Search API

## Search Archives

> Search for Archives. You can use the IDs of this JSON with the other endpoints.

```json
{"openapi":"3.1.0","info":{"title":"LANraragi API","version":"0.9.6"},"tags":[{"name":"search","description":"Perform searches."}],"servers":[{"url":"https://lrr.tvc-16.science/api"}],"paths":{"/search":{"get":{"operationId":"searchArchives","summary":"Search Archives","description":"Search for Archives. You can use the IDs of this JSON with the other endpoints.","tags":["search"],"parameters":[{"name":"category","in":"query","required":false,"description":"ID of the category you want to restrict this search to.","schema":{"type":"string","minLength":14,"maxLength":14}},{"name":"filter","in":"query","required":false,"description":"Search query. You can use the following special characters in it:\n\n**Quotation Marks (\"...\")**\nExact string search. Allows a search term to include spaces. Everything placed inside a pair of quotation marks is treated as a singular term. Wildcard characters are still interpreted as wildcards.\n\n**Question Mark (?), Underscore (_)**\nWildcard. Can match any single character.\n\n**Asterisk (*), Percentage Sign (%)**\nWildcard. Can match any sequence of characters (including none).\n\n**Subtraction Sign (-)**\nExclusion. When placed before a term, prevents search results from including that term.\n\n**Dollar Sign ($)**\nAdd at the end of a tag to perform an exact tag search rather than displaying all elements that start with the term. Only matches tags regardless of search parameters and can be used as an exclusion to ignore misc tags in the search query.","schema":{"type":"string"}},{"name":"start","in":"query","required":false,"description":"From which archive in the total result count this enumeration should start. The total number of archives displayed depends on the server-side page size preference.  \n\nFrom 0.8.2 onwards, you can use \"-1\" here to get the full, unpaged data.","schema":{"type":"integer"}},{"name":"sortby","in":"query","required":false,"description":"Namespace by which you want to sort the results. There are specific sort keys you can use:\n- *title* if you want to sort by title\n- *lastread* if you want to sort by last read time. (If **Server-side Progress Tracking** is enabled)  \n\n(Default value is title. If you sort by lastread, IDs that have never been read will be removed from the search.)","schema":{"type":"string"}},{"name":"order","in":"query","required":false,"description":"Order of the sort, either `asc` or `desc`.","schema":{"type":"string"}},{"name":"newonly","in":"query","required":false,"description":"Limit search to new archives only.","schema":{"type":"boolean"}},{"name":"untaggedonly","in":"query","required":false,"description":"Limit search to untagged archives only.","schema":{"type":"boolean"}},{"name":"hidecompleted","in":"query","required":false,"description":"Hide archives where reading progress has reached the end.","schema":{"type":"boolean"}},{"name":"groupby_tanks","in":"query","required":false,"default":false,"description":"Enable or disable Tankoubon grouping. Defaults to true.\nWhen enabled, Tankoubons will show in search results, replacing all the archive IDs they contain.","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Search results","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","description":"Archive metadata objects for each search result","items":{"$ref":"#/components/schemas/ArchiveMetadataJson"}},"recordsFiltered":{"type":"integer","description":"Amount of archives in the search result"},"recordsTotal":{"type":"integer","description":"Total number of archives available. This result will change depending on the `groupby_tanks` parameter."}}}}}},"204":{"description":"Search engine is not initialized yet. Please wait a few seconds."}}}}},"components":{"schemas":{"ArchiveMetadataJson":{"type":"object","description":"JSON object for archive metadata for most API responses","required":["arcid","title","filename","tags","isnew","extension","progress","pagecount","lastreadtime","size"],"properties":{"arcid":{"type":"string","description":"Unique identifier for the archive (40-char SHA1) or tankoubon (15-char TANK_* ID)","oneOf":[{"minLength":40,"maxLength":40,"pattern":"^[0-9a-f]{40}$"},{"minLength":15,"maxLength":15,"pattern":"^TANK_[0-9]{10}$"}]},"title":{"type":"string","description":"Title of the archive"},"filename":{"type":"string","description":"Filename of the archive"},"tags":{"type":"string","description":"Comma-separated list of tags associated with the archive"},"summary":{"type":"string","nullable":true,"description":"Summary description of the archive"},"isnew":{"oneOf":[{"type":"boolean"},{"type":"string"}],"nullable":true,"description":"Whether the archive is newly added."},"extension":{"type":"string","description":"File extension of the archive"},"progress":{"type":"integer","description":"Reading progress (page number)"},"pagecount":{"type":"integer","description":"Total number of pages in the archive"},"lastreadtime":{"type":"integer","description":"Unix timestamp of when the archive was last read"},"size":{"type":"integer","description":"Size of the archive in bytes"},"toc":{"type":"array","description":"Table of contents for the archive"}}}}}}
```

## Search random Archives

> Get randomly selected Archives from the given filter and/or category.

```json
{"openapi":"3.1.0","info":{"title":"LANraragi API","version":"0.9.6"},"tags":[{"name":"search","description":"Perform searches."}],"servers":[{"url":"https://lrr.tvc-16.science/api"}],"paths":{"/search/random":{"get":{"operationId":"searchRandomArchives","summary":"Search random Archives","description":"Get randomly selected Archives from the given filter and/or category.","tags":["search"],"parameters":[{"name":"category","in":"query","required":false,"description":"ID of the category you want to restrict this search to.","schema":{"type":"string","minLength":14,"maxLength":14}},{"name":"filter","in":"query","required":false,"description":"Search query. This follows the same rules as the queries in `/api/search`.","schema":{"type":"string"}},{"name":"count","in":"query","required":false,"default":5,"description":"How many archives you want to pull randomly. Defaults to 5.  \n\nIf the search doesn't return enough data to match your count, you will get the full search shuffled randomly.","schema":{"type":"integer"}},{"name":"newonly","in":"query","required":false,"description":"Limit search to new archives only.","schema":{"type":"boolean"}},{"name":"untaggedonly","in":"query","required":false,"description":"Limit search to untagged archives only.","schema":{"type":"boolean"}},{"name":"hidecompleted","in":"query","required":false,"description":"Hide archives where reading progress has reached the end.","schema":{"type":"boolean"}},{"name":"groupby_tanks","in":"query","required":false,"description":"Enable or disable Tankoubon grouping. Defaults to true.\nWhen enabled, Tankoubons will show in search results, replacing all the archive IDs they contain.","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Search results","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","description":"Archive metadata objects for each search result","items":{"$ref":"#/components/schemas/ArchiveMetadataJson"}},"recordsTotal":{"type":"integer"}}}}}}}}}},"components":{"schemas":{"ArchiveMetadataJson":{"type":"object","description":"JSON object for archive metadata for most API responses","required":["arcid","title","filename","tags","isnew","extension","progress","pagecount","lastreadtime","size"],"properties":{"arcid":{"type":"string","description":"Unique identifier for the archive (40-char SHA1) or tankoubon (15-char TANK_* ID)","oneOf":[{"minLength":40,"maxLength":40,"pattern":"^[0-9a-f]{40}$"},{"minLength":15,"maxLength":15,"pattern":"^TANK_[0-9]{10}$"}]},"title":{"type":"string","description":"Title of the archive"},"filename":{"type":"string","description":"Filename of the archive"},"tags":{"type":"string","description":"Comma-separated list of tags associated with the archive"},"summary":{"type":"string","nullable":true,"description":"Summary description of the archive"},"isnew":{"oneOf":[{"type":"boolean"},{"type":"string"}],"nullable":true,"description":"Whether the archive is newly added."},"extension":{"type":"string","description":"File extension of the archive"},"progress":{"type":"integer","description":"Reading progress (page number)"},"pagecount":{"type":"integer","description":"Total number of pages in the archive"},"lastreadtime":{"type":"integer","description":"Unix timestamp of when the archive was last read"},"size":{"type":"integer","description":"Size of the archive in bytes"},"toc":{"type":"array","description":"Table of contents for the archive"}}}}}}
```

## 🔑 Discard Search Cache

> Discard the cache containing previous user searches.

```json
{"openapi":"3.1.0","info":{"title":"LANraragi API","version":"0.9.6"},"tags":[{"name":"search","description":"Perform searches."}],"servers":[{"url":"https://lrr.tvc-16.science/api"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{"api_key":{"type":"apiKey","name":"Authorization","in":"header","description":"Use Authorization: Bearer <base64(api_key)>"}},"schemas":{"OperationResponse":{"type":"object","required":["operation","success"],"properties":{"operation":{"type":"string","description":"Name of operation"},"error":{"type":"string","description":"Error message if any"},"successMessage":{"type":"string","description":"Success message if any"},"success":{"type":"integer","description":"Returns 1 if operation was successful, else 0","enum":[0,1]}}}}},"paths":{"/search/cache":{"delete":{"operationId":"discardSearchCache","summary":"🔑 Discard Search Cache","description":"Discard the cache containing previous user searches.","tags":["search"],"responses":{"200":{"description":"Success response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OperationResponse"}}}},"400":{"description":"No archive ID response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OperationResponse"}}}}}}}}}
```
