Hướng dẫn sử dụng
Plugin thay thế toàn bộ tìm kiếm sản phẩm WooCommerce mặc định bằng Typesense — tìm kiếm tức thời, lọc đa chiều, giảm tải MySQL.
Cài đặt
Có 2 cách cài đặt plugin Typesense for WooCommerce:
Cách 1: Clone từ GitHub (khuyến nghị)
# SSH vào server, vào thư mục plugins
cd wp-content/plugins/
git clone https://github.com/codetot-web/typesense-for-woocommerce.git
cd typesense-for-woocommerce
composer install --no-dev --optimize-autoloader
Cách 2: Composer trong project
# Thêm vào composer.json của project
composer require codetot-web/typesense-for-woocommerce
Sau khi cài, vào WP Admin → WooCommerce → Typesense Search → kích hoạt và cấu hình.
Cấu hình cơ bản
- Vào WooCommerce → Typesense Search
- Nhập thông tin Typesense server:
- Host — Địa chỉ Typesense server (IP hoặc hostname)
- Port — Cổng Typesense (mặc định:
8108) - Protocol — HTTP hoặc HTTPS
- API Key — Typesense API key (quyền search + document write)
- Click Test Connection để kiểm tra kết nối
- Click Create/Update Collection để tạo schema sản phẩm
- Chọn Sync Frequency: 15 phút, hàng giờ, hoặc hàng ngày
- Click Sync All Products Now để index toàn bộ catalog
Tính năng chính
Instant Search
Tìm kiếm sản phẩm tức thời thay thế WC search mặc định. Kết quả trả về trong <50ms từ Typesense.
Autocomplete
Gợi ý sản phẩm khi gõ — dropdown hiển thị thumbnail, tên, giá. Debounce 300ms, tối thiểu 2 ký tự.
Faceted Filtering
Lọc theo danh mục, khoảng giá, tình trạng kho, thuộc tính, đánh giá — tất cả từ Typesense.
Real-time Sync
Index ngay lập tức khi thêm/sửa/xoá sản phẩm. Hook vào save_post, import, trash.
Batch Sync (WP-Cron)
Đồng bộ định kỳ qua WP-Cron. Queue-based — xử lý các sản phẩm chờ sync trước.
Graceful Degradation
Tự động fallback về WC search mặc định nếu Typesense không available. Không mất dữ liệu.
Collection Schema (28 fields)
Plugin tự động tạo collection woocommerce_products với 28 fields được tối ưu cho search:
facet = có thể dùng làm bộ lọc
Câu hỏi thường gặp
Plugin có yêu cầu Typesense Cloud không?
Không. Plugin được thiết kế cho Typesense self-hosted, phù hợp với LiteSoup server stack. Có thể dùng Typesense Cloud nếu muốn.
Chuyện gì xảy ra nếu Typesense bị downtime?
Plugin tự động fallback về WooCommerce search mặc định (MySQL). Cửa hàng vẫn hoạt động bình thường, không mất sản phẩm.
Có hỗ trợ biến thể sản phẩm không?
Có. Tất cả product types (simple, variable, grouped, external) đều được index và tìm kiếm.
Có tương thích WPML/Polylang không?
Có. Plugin bao gồm WPML và Polylang compatibility layer cho tìm kiếm đa ngôn ngữ.
Làm sao để cài Typesense server?
Xem tab DevOps để biết hướng dẫn cài đặt Typesense server chi tiết.
Hướng dẫn DevOps
Cấu hình Typesense server, deployment pipeline, automation và troubleshooting.
Requirements
- WordPress ≥ 6.0
- WooCommerce ≥ 8.0
- PHP ≥ 8.0
- Typesense Server ≥ 28.0 (self-hosted)
- Composer (để cài typesense-php)
Cài đặt Typesense Server
Quick install (Linux x86_64)
# Tải và chạy Typesense single-node curl -fsSL https://dl.typesense.org/releases/28.0/typesense-server-28.0-linux-amd64.tar.gz -o typesense.tar.gz tar -xzf typesense.tar.gz sudo mv typesense-server /usr/local/bin/ # Tạo data directory sudo mkdir -p /var/lib/typesense sudo useradd -r -s /bin/false typesense sudo chown -R typesense:typesense /var/lib/typesense # Systemd service sudo tee /etc/systemd/system/typesense-server.service <<'EOF' [Unit] Description=Typesense Search Server After=network.target [Service] Type=simple User=typesense Group=typesense ExecStart=/usr/local/bin/typesense-server \ --data-dir=/var/lib/typesense \ --api-key=YOUR_API_KEY \ --listen-port=8108 \ --enable-cors Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now typesense-server # Kiểm tra curl http://localhost:8108/health
Docker (alternative)
docker run -d --name typesense \ -p 8108:8108 \ -v typesense-data:/data \ typesense/typesense:28.0 \ --data-dir /data \ --api-key=YOUR_API_KEY \ --listen-port 8108 \ --enable-cors
Deployment pipeline
Add vào deployment script của dự án:
#!/bin/bash # deploy-typesense-wc.sh SITE_PATH=/var/www/example.com # Clone/update plugin if [ -d "$SITE_PATH/wp-content/plugins/typesense-for-woocommerce" ]; then cd "$SITE_PATH/wp-content/plugins/typesense-for-woocommerce" git pull origin main else git clone https://github.com/codetot-web/typesense-for-woocommerce.git "$SITE_PATH/wp-content/plugins/typesense-for-woocommerce" cd "$SITE_PATH/wp-content/plugins/typesense-for-woocommerce" fi composer install --no-dev --optimize-autoloader # Activate plugin wp plugin activate typesense-for-woocommerce --path="$SITE_PATH" # Verify Typesense connection wp eval 'echo \TypesenseForWooCommerce\Plugin::get_instance()->get_client()->test_connection()["success"] ? "OK\\n" : "FAIL\\n";' --path="$SITE_PATH"
Typesense Resource Requirements
| Catalog Size | RAM | Disk | CPU | Notes |
|---|---|---|---|---|
| < 10K products | 512 MB | 1 GB | 1 core | Shared hosting OK |
| 10K – 100K products | 1–2 GB | 5 GB | 2 cores | VPS nhỏ |
| 100K – 1M products | 4–8 GB | 20 GB | 4 cores | VPS lớn / dedicated |
| > 1M products | 16+ GB | 50+ GB | 8+ cores | Cluster |
Automation
Các AJAX endpoints có thể dùng trong automation scripts:
| Endpoint | Action | Method |
|---|---|---|
admin-ajax.php | ts4wc_test_connection | POST |
admin-ajax.php | ts4wc_create_collection | POST |
admin-ajax.php | ts4wc_sync_all | POST |
admin-ajax.php | ts4wc_autocomplete | POST (public) |
WP-Cron schedule
# Cron: batch sync (nếu dùng tần suất tuỳ chỉnh) 0 */2 * * * wp cron event run ts4wc_batch_sync --path=/var/www/example.com # Verify collection health curl -X GET "http://localhost:8108/collections/woocommerce_products" \ -H "X-TYPESENSE-API-KEY: YOUR_API_KEY" | jq '.num_documents'
Troubleshooting
Connection failed
Kiểm tra: Typesense server đang chạy (systemctl status typesense-server), port 8108 mở (firewall), API key đúng, CORS enabled.
Products không sync
Kiểm tra: "Enable Sync" được bật, Typesense API key có quyền document write, WP-Cron hoạt động (nếu dùng batch mode).
Search không trả về kết quả
Kiểm tra collection đã được tạo và có documents (curl /collections/woocommerce_products). Thử re-index từ admin.
Typesense server crash
Kiểm tra RAM — Typesense cần đủ RAM để giữ index trong memory. Xem resource requirements ở trên.
Marketing Toolkit
Tính năng, USP, messaging và tài liệu cho team Marketing.
Giới thiệu ngắn
Typesense for WooCommerce là plugin WordPress mã nguồn mở (GPLv2) giúp offload toàn bộ tìm kiếm và lọc sản phẩm WooCommerce từ MySQL sang Typesense — một search engine hiệu năng cao, cho tốc độ truy vấn dưới 50ms. Plugin hỗ trợ instant search, autocomplete dropdown, faceted filtering (danh mục, giá, thuộc tính), real-time sync, và graceful degradation khi Typesense không available.
USP (Unique Selling Points)
100% Mã nguồn mở
GPLv2. Không premium, không upsell, không tính năng khoá. Tất cả tính năng đều miễn phí.
Sub-50ms search
Tìm kiếm sản phẩm trong <50ms — nhanh hơn 10-50 lần so với MySQL LIKE query.
Graceful Degradation
Typesense down? Plugin tự động fallback về WC search mặc định. Không mất doanh thu.
Faceted Search
Lọc đa chiều từ Typesense — category, price, stock, attributes, rating. Không cần plugin filter riêng.
WPML/Polylang Ready
Tìm kiếm đa ngôn ngữ out-of-the-box. Hỗ trợ WPML và Polylang.
Self-hosted Typesense
Không lock-in vào search cloud service. Typesense tự chạy trên VPS của bạn.
Target audiences
| Audience | Pain point | Solution | Message |
|---|---|---|---|
| WooCommerce store owners | Search chậm, MySQL không scale với catalog lớn | Typesense search engine, sub-50ms | "Search nhanh hơn 50 lần" |
| Web developers | MySQL load cao do search queries, cần giải pháp offload | Offload search khỏi MySQL, giảm server load | "Giảm 90% search load trên MySQL" |
| Agency owners | Client stores cần search nhanh, filter phức tạp | Plugin trọn gói, dễ deploy, CLI-friendly | "Một plugin cho tất cả client" |
| LiteSoup users | Đang dùng LiteSoup stack, muốn search engine tích hợp | Typesense pre-configured cho LiteSoup | "Typesense + LiteSoup = search stack hoàn chỉnh" |
Competitor comparison
| Tính năng | Typesense for WC | Search with Typesense | SearchWP | ElasticPress |
|---|---|---|---|---|
| Giá | Free (GPLv2) | Free (core) + $49/yr (addon) | $99/năm | $79+/năm |
| Mã nguồn mở | ✅ | ✅ (core) | ❌ | ✅ |
| Search Engine | Typesense | Typesense | Custom index | Elasticsearch |
| Instant Search | ✅ | ✅ (premium) | ❌ | ✅ |
| Autocomplete | ✅ | ✅ (premium) | ✅ | ✅ |
| Faceted Filter | ✅ | ✅ (premium) | ❌ | ✅ |
| Real-time Sync | ✅ | ✅ | ✅ | ✅ |
| Graceful Degradation | ✅ | ❌ | N/A | ❌ |
| WPML/Polylang | ✅ | ✅ (premium) | ✅ | ✅ |
| Self-hosted Engine | ✅ Typesense | ✅ Typesense | N/A | ❌ ES Cloud |
Content Plan & Use Cases
Ý tưởng bài viết, hướng dẫn, case study cho team Content.
Blog post ideas
Cài đặt Typesense + WooCommerce search trong 15 phút
Hướng dẫn từ A-Z: cài Typesense server, cấu hình plugin, index sản phẩm.
Typesense vs Elasticsearch cho WooCommerce — Nên chọn cái nào?
So sánh hiệu năng, tài nguyên, độ phức tạp. Typesense nhẹ hơn, dễ cài hơn.
Giảm 90% MySQL load với Typesense search offload
Case study: site 50K products, search queries chiếm 70% DB load → offload thành công.
Tối ưu WooCommerce search: Từ 2 giây xuống 50ms
Before/after benchmark: MySQL LIKE vs Typesense search, với số liệu thực tế.
Typesense trên LiteSoup: Search engine tích hợp cho WordPress
Hướng dẫn cài Typesense như một service trong LiteSoup stack.
Faceted search cho WooCommerce: Lọc sản phẩm không cần plugin rời
Typesense cho phép lọc theo category, price, stock, attributes — tất cả trong 1 plugin.
Use cases
1. Cửa hàng thời trang (nhiều biến thể)
Hàng nghìn sản phẩm với nhiều size, màu sắc. Typesense cho phép lọc theo attribute (size, color) tức thời, không cần page reload.
2. Marketplace / Multi-vendor
Hàng trăm nghìn sản phẩm từ nhiều vendor. Typesense search + faceted filter giúp người mua tìm đúng sản phẩm trong vài mili giây.
3. Cửa hàng điện tử (nhiều thông số kỹ thuật)
Sản phẩm có nhiều thuộc tính (RAM, CPU, dung lượng). Typesense attribute filtering cho phép lọc chính xác theo thông số.
4. Site đa ngôn ngữ (WPML)
Typesense hỗ trợ multilingual search. Plugin tích hợp WPML/Polylang — search ra kết quả đúng ngôn ngữ người dùng.
5. LiteSoup hosting stack
Typesense là search engine được khuyến nghị cho LiteSoup. Plugin tích hợp sẵn, chỉ cần cài Typesense server là chạy.
Social media posts
📱 Thread (X/Twitter) — Tính năng:
🧵 Typesense for WooCommerce là gì?
1/ Plugin WordPress miễn phí, mã nguồn mở (GPLv2)
2/ Offload search khỏi MySQL → Typesense engine
3/ Sub-50ms search, autocomplete, faceted filter
4/ Real-time sync + WP-Cron batch sync
5/ Graceful degradation — Typesense down? Tự động fallback 🛡️
6/ WPML/Polylang ready. Self-hosted Typesense, không lock-in 🔓
📘 LinkedIn — DevOps góc nhìn:
Your WooCommerce store has 50K products. Search takes 2 seconds. MySQL is dying.
Typesense for WooCommerce fixes this. One plugin. Free. GPLv2.
✅ Instant search in <50ms
✅ Faceted filters (category, price, stock, attributes)
✅ Real-time sync + WP-Cron batch
✅ Graceful fallback to MySQL
Built by CODE TOT for production WooCommerce.
👉 github.com/codetot-web/typesense-for-woocommerce
API & Integration Reference
Tài liệu đầy đủ về AJAX endpoints, hooks, filters và integration API của Typesense for WooCommerce.
AJAX Endpoints
Plugin cung cấp các AJAX endpoints cho frontend và admin:
ts4wc_autocomplete (public)
PUBLIC — Tìm kiếm gợi ý sản phẩm cho autocomplete dropdown.
| Field | Type | Required | Description |
|---|---|---|---|
action | string | ✅ | ts4wc_autocomplete |
query | string | ✅ | Search query (min 2 ký tự) |
nonce | string | ✅ | Frontend nonce (ts4wc_frontend_nonce) |
# Example response
{
"success": true,
"data": [
{
"product_id": 123,
"title": "Áo thun nam",
"sku": "AT-001",
"price": "250000",
"permalink": "https://...",
"thumbnail_url": "https://...",
"stock_status": "instock"
}
]
}
ts4wc_test_connection (admin)
ADMIN — Kiểm tra kết nối đến Typesense server.
# Response mẫu { "success": true, "data": { "message": "Connection successful" } } # Hoặc nếu lỗi { "success": false, "data": { "message": "Connection refused" } }
ts4wc_create_collection (admin)
ADMIN — Tạo hoặc cập nhật collection schema woocommerce_products.
ts4wc_sync_all (admin)
ADMIN — Đồng bộ toàn bộ sản phẩm lên Typesense.
WordPress Hooks
Filters
| Hook | Params | Description |
|---|---|---|
ts4wc_search_query | $query (array) | Modify search query before sending to Typesense |
ts4wc_search_results | $results (array) | Modify search results before returning to WP |
ts4wc_product_data | $data (array), $product_id (int) | Modify product data before indexing |
ts4wc_batch_size | $size (int) | Override batch sync size (default: 50) |
ts4wc_min_query_length | $length (int) | Minimum characters for autocomplete (default: 2) |
Actions
| Hook | Params | Description |
|---|---|---|
ts4wc_before_sync | $product_ids (array) | Fires before batch sync starts |
ts4wc_after_sync | $product_ids (array), $result (array) | Fires after batch sync completes |
ts4wc_sync_error | $product_id (int), $error (string) | Fires when a product fails to sync |
ts4wc_collection_created | $schema (array) | Fires after collection is created/updated |
Collection Schema
Typesense collection woocommerce_products — 28 fields, default sorting by menu_order:
{
"name": "woocommerce_products",
"default_sorting_field": "menu_order",
"enable_nested_fields": true,
"fields": [
{ "name": "product_id", "type": "int32", "facet": false },
{ "name": "title", "type": "string", "facet": false },
{ "name": "description", "type": "string", "facet": false },
{ "name": "short_description","type": "string", "facet": false },
{ "name": "sku", "type": "string", "facet": false },
{ "name": "slug", "type": "string", "facet": false },
{ "name": "price", "type": "float", "facet": true },
{ "name": "sale_price", "type": "float", "facet": false },
{ "name": "regular_price", "type": "float", "facet": false },
{ "name": "on_sale", "type": "bool", "facet": true },
{ "name": "in_stock", "type": "bool", "facet": true },
{ "name": "stock_status", "type": "string", "facet": true },
{ "name": "categories", "type": "string[]","facet": true },
{ "name": "category_ids", "type": "int32[]", "facet": true },
{ "name": "tags", "type": "string[]","facet": true },
{ "name": "attributes", "type": "object", "facet": false },
{ "name": "attribute_names", "type": "string[]","facet": true },
{ "name": "attribute_values", "type": "string[]","facet": true },
{ "name": "type", "type": "string", "facet": true },
{ "name": "featured", "type": "bool", "facet": true },
{ "name": "rating", "type": "float", "facet": false },
{ "name": "review_count", "type": "int32", "facet": false },
{ "name": "menu_order", "type": "int32", "facet": false },
{ "name": "permalink", "type": "string", "facet": false },
{ "name": "thumbnail_url", "type": "string", "facet": false },
{ "name": "gallery_urls", "type": "string[]","facet": false },
{ "name": "stock_quantity", "type": "int32", "facet": false },
{ "name": "brand", "type": "string", "facet": false }
]
}
Frontend JS Config
Plugin passes config to frontend via ts4wcConfig global:
{
apiKey: "YOUR_API_KEY",
host: "localhost",
port: 8108,
protocol: "http",
collection: "woocommerce_products",
searchPage: "https://example.com/shop/",
ajaxUrl: "https://example.com/wp-admin/admin-ajax.php",
nonce: "FRONTEND_NONCE",
isSearchPage: false,
isShop: true
}
Best practices
🔄 Deployment flow
git pull → composer install → wp plugin activate → verify connection
⏰ Cron schedule
Batch sync mỗi 15 phút cho store động, hàng giờ cho store ít biến động.
🧪 Pre-launch check
Test connection → Create collection → Sync all → Verify search results → Test fallback