# Autocomplete

> Search as you type, with an unfinished last word.

`GET /v1/autocomplete` is like `/v1/search`, but the last word of `text` is treated as unfinished and matches as a prefix. `shaniwar wa` finds Shaniwar Wada.

## Parameters

| Parameter | Type | Default | Meaning |
| --- | --- | --- | --- |
| `text` | string | required | Place name, address, or both. Only letters and digits count; at most 12 words are used. |
| `size` | integer 1–40 | `10` | Number of results. |
| `layers` | list | all | Comma-separated: `venue` (points of interest), `address`, `street` (no geolith build writes streets yet), `locality` (cities, towns, villages), `county`, `region`, `country`. |
| `boundary.country` | list | every country | Comma-separated ISO 3166-1 alpha-2 codes, any case. |
| `focus.point.lat` | number −90–90 | none | Latitude of a point whose surroundings rank higher. Set with `focus.point.lon`. |
| `focus.point.lon` | number −180–180 | none | Longitude of that point. Set with `focus.point.lat`. |

## Example

```bash
curl 'http://localhost:4000/v1/autocomplete?text=shaniwar%20wa&size=2'
```

```json
{
  "bbox": [
    73.8490348,
    18.5196488,
    73.855376,
    18.5232435
  ],
  "features": [
    {
      "geometry": {
        "coordinates": [
          73.855376,
          18.5196488
        ],
        "type": "Point"
      },
      "properties": {
        "confidence": 1.0,
        "country": "India",
        "country_code": "IN",
        "county": "Pune",
        "gid": "geolith:venue:5690416219557866379",
        "id": "5690416219557866379",
        "importance": 0.9390000104904175,
        "label": "Shaniwar Wada, Pune, Maharashtra, India",
        "layer": "venue",
        "locality": "Pune",
        "name": "Shaniwar Wada",
        "region": "Maharashtra",
        "source": "geolith"
      },
      "type": "Feature"
    },
    {
      "geometry": {
        "coordinates": [
          73.8490348,
          18.5232435
        ],
        "type": "Point"
      },
      "properties": {
        "confidence": 1.0,
        "country": "India",
        "country_code": "IN",
        "county": "Pune",
        "gid": "geolith:venue:7254043780672488050",
        "id": "7254043780672488050",
        "importance": 0.9943000078201294,
        "label": "Hotel Swan Inn Near Shaniwar Wada, Pune, Maharashtra, India",
        "layer": "venue",
        "locality": "Pune",
        "name": "Hotel Swan Inn Near Shaniwar Wada",
        "region": "Maharashtra",
        "source": "geolith"
      },
      "type": "Feature"
    }
  ],
  "geocoding": {
    "attribution": "https://console.geolith.app/attribution",
    "engine": {
      "name": "geolith-search",
      "version": "0.1.0"
    },
    "query": {
      "ranking": "importance",
      "size": 2,
      "text": "shaniwar wa"
    },
    "version": "0.2"
  },
  "type": "FeatureCollection"
}
```

The response is trimmed to two features.

## How the last word matches

- The last word matches as a prefix. The file keeps a posting list for every word prefix of 4 to 6 characters, and a short list of the most important places for every prefix of 2 or 3 characters, so a lone short prefix reads one list. After other words, a 2- or 3-character prefix is checked against a small prefix signature stored with each place, and a 1-character last word is checked on the place text.
- The last word stays required even when the other words relax.
- The other words match as whole words.
