-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-test.sql
More file actions
56 lines (44 loc) · 2.79 KB
/
init-test.sql
File metadata and controls
56 lines (44 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- Initialize test database and run tests
-- This script runs automatically when the PostgreSQL container starts
-- Create the extension
CREATE EXTENSION pg_bleve;
-- Create a test table
CREATE TABLE mock_items (
id SERIAL PRIMARY KEY,
description TEXT,
category TEXT,
rating INTEGER,
in_stock BOOLEAN,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
metadata JSONB
);
-- Insert test data
INSERT INTO mock_items (description, category, rating, in_stock, metadata) VALUES
('Wireless Bluetooth Headphones', 'Electronics', 4, true, '{"brand": "Sony", "color": "black"}'),
('Running Shoes Nike Air Max', 'Sports', 5, true, '{"brand": "Nike", "size": "10"}'),
('Coffee Maker Programmable', 'Home', 3, false, '{"brand": "Breville", "capacity": "12 cups"}'),
('Smartphone iPhone 15', 'Electronics', 5, true, '{"brand": "Apple", "storage": "128GB"}'),
('Yoga Mat Non-slip', 'Sports', 4, true, '{"brand": "Lululemon", "thickness": "5mm"}');
-- Create Bleve index
SELECT bleve_create_index('mock_items', '{"key_field": "id"}');
-- Index documents
SELECT bleve_index_document('mock_items', '1', '{"id": "1", "description": "Wireless Bluetooth Headphones", "category": "Electronics", "rating": 4, "in_stock": true, "metadata": {"brand": "Sony", "color": "black"}}');
SELECT bleve_index_document('mock_items', '2', '{"id": "2", "description": "Running Shoes Nike Air Max", "category": "Sports", "rating": 5, "in_stock": true, "metadata": {"brand": "Nike", "size": "10"}}');
SELECT bleve_index_document('mock_items', '3', '{"id": "3", "description": "Coffee Maker Programmable", "category": "Home", "rating": 3, "in_stock": false, "metadata": {"brand": "Breville", "capacity": "12 cups"}}');
SELECT bleve_index_document('mock_items', '4', '{"id": "4", "description": "Smartphone iPhone 15", "category": "Electronics", "rating": 5, "in_stock": true, "metadata": {"brand": "Apple", "storage": "128GB"}}');
SELECT bleve_index_document('mock_items', '5', '{"id": "5", "description": "Yoga Mat Non-slip", "category": "Sports", "rating": 4, "in_stock": true, "metadata": {"brand": "Lululemon", "thickness": "5mm"}}');
-- Test search functionality
\echo 'Testing pg_bleve extension...'
\echo 'Search for electronics:'
SELECT bleve_search('mock_items', 'category:Electronics');
\echo 'Search for Apple products:'
SELECT bleve_search('mock_items', 'metadata.brand:Apple');
\echo 'Search for wireless products:'
SELECT bleve_search('mock_items', 'description:wireless');
\echo 'Testing @@@ operator:'
SELECT 'mock_items' @@@ 'category:Electronics' as has_electronics;
SELECT 'mock_items' @@@ 'metadata.brand:Apple' as has_apple_products;
SELECT 'mock_items' @@@ 'description:wireless' as has_wireless_products;
\echo 'All indexed documents:'
SELECT bleve_search('mock_items', '*');
\echo 'pg_bleve extension test completed successfully!'