Search Autocomplete Setup for Bitrix CMS
Search autocomplete — completing a typed query into a full search term — differs from suggestions: suggestions show specific products or pages, autocomplete proposes query variants. In Bitrix, these concepts are often confused, and implementation depends on which functionality is actually needed.
Two Autocomplete Scenarios
Scenario 1: Autocomplete by Search Index
User types "red", system suggests: "red dresses", "red sneakers", "red couch". Source — titles from b_search_content.
Scenario 2: Autocomplete by Query History
System suggests popular queries from other users matching typed characters. Source — search history from b_search_user_trans (if history tracking enabled).
The standard bitrix:search.suggest component implements scenario 1. Scenario 2 requires custom development.
Enabling Search History
Settings → Search → Module Settings → Save search history — enable.
History is saved in b_search_user_trans. Fields: SITE_ID, WORD (search query), DATE_CHANGE, POPULARITY (repeat count).
Implementing Autocomplete by Popular Queries
AJAX endpoint for autocomplete by history:
// /local/ajax/search_autocomplete.php
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
$query = trim($_GET['q']);
if (strlen($query) < 2) {
die(json_encode([]));
}
$result = \Bitrix\Main\Application::getConnection()->query(
"SELECT WORD, POPULARITY FROM b_search_user_trans
WHERE SITE_ID = '" . SITE_ID . "'
AND WORD LIKE '" . \Bitrix\Main\DB\MssqlConnection::ForSql($query) . "%'
ORDER BY POPULARITY DESC
LIMIT 10"
);
$suggestions = [];
while ($row = $result->fetch()) {
$suggestions[] = $row['WORD'];
}
echo json_encode($suggestions);
Frontend — standard input with input event handler and 200–300 ms debounce.
Combining Suggestions and Autocomplete
In practice, the most convenient UX is a combined dropdown:
- Top section: 3–5 popular queries (autocomplete)
- Bottom section: 5–7 specific products (suggestions with images)
Implemented via two parallel AJAX requests or single endpoint returning both data types.
Caching
Autocomplete requests execute with each character input — important to cache responses. Options:
- Bitrix cache (
\Bitrix\Main\Data\Cache) with 30–60 minute TTL - Redis/Memcached for storing popular queries
- Static files for top-100 popular queries (updated by agent hourly)
Implementation Timeline
Standard autocomplete setup via suggestions component — 1–2 hours. Custom autocomplete by query history with combined UI — 4–8 hours.







