# Autocomplete

The Autocomplete feature allows you to retrieve the most relevant products and categories based on a user's search query. This guide outlines how to use this feature to enhance search functionality in your application. By sending a `GET` request with a specific search text to the provided endpoint, you can retrieve a structured response containing product and category suggestions. This guide also provides insights into filtering options and customization settings to optimize search results for your application.

### `GET` Most Relevant Products via Searched Text

Returns the most relevant products and categories upon searching the word sent with ‘search\_text.’

**Path:** `https://{commerce_url}/autocomplete/?search_text=<SEARCH_TEXT>`

**Example Response**

```json
{
"groups": [
    	{
        	"entries": [
            	{
                	"label": "Electro Guitar",
                	"url": "/electro-guitar/",
                	"suggestion_type": "category",
                	"extra": {
                    	"category_id": 3,
                    	"parent_categories": [
                        	"Music"
                    	]
                	}
            	},
            	…
        	],
        	"suggestion_type": "Category"
    	},
    	{
        	"entries": [
            	{
                	"label": "Bass Guitar",
                	"url": "/bass-guitar/",
                	"suggestion_type": "product",
                	"extra": {
                    	"image": null,
                    	"retail_price": 249.98,
                    	"product_type": 1,
                    	"price": 99.99
                	}
            	},
            	…
        	],
        	"suggestion_type": "Product"
    	}
	]
}
```

Filtering is limited to the first four words of the search text; any additional words are disregarded.

Additionally, there are customizable settings available to refine the filtering of the most relevant products and categories. These settings are evaluated using the `and` logical operator in conjunction with the search text. The following sections provide insights into these settings.

#### Product Filtering

For products, the provided search text is compared to the `name` field as an exact match and the `search_text` field as a prefix match, utilizing the `or` logical operator.

#### Category Filtering

When filtering categories, the provided search text is divided by spaces, and each word is compared to the `name` field of the categories using a case-insensitive contain lookup operator. The results are then evaluated with the `and` logical operator.

**Custom Settings**

The `CATEGORY_PRE_FILTER` is used to configure Django Q object or its combination.

**Example**

```py
CATEGORY_PRE_FILTER = Q(path__startswith='000100010') | Q(order=1)
```

In this example, the system will return categories that match the search text and meet one of two conditions: either the path starts with `000100010` or the order equals `1`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/commerce/autocomplete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
