#!/bin/bash # Simple Tantivy Search Integration Test for HeroDB # This script tests the full-text search functionality we just integrated set -e echo "๐Ÿ” Testing Tantivy Search Integration..." # Build the project first echo "๐Ÿ“ฆ Building HeroDB..." cargo build --release # Start the server in the background echo "๐Ÿš€ Starting HeroDB server on port 6379..." cargo run --release -- --port 6379 --dir ./test_data & SERVER_PID=$! # Wait for server to start sleep 3 # Function to cleanup on exit cleanup() { echo "๐Ÿงน Cleaning up..." kill $SERVER_PID 2>/dev/null || true rm -rf ./test_data exit } # Set trap for cleanup trap cleanup EXIT INT TERM # Function to execute Redis command execute_cmd() { local cmd="$1" local description="$2" echo "๐Ÿ“ $description" echo " Command: $cmd" if result=$(redis-cli -p 6379 $cmd 2>&1); then echo " โœ… Result: $result" echo return 0 else echo " โŒ Failed: $result" echo return 1 fi } echo "๐Ÿงช Running Tantivy Search Tests..." echo # Test 1: Create a search index execute_cmd "ft.create books SCHEMA title TEXT description TEXT author TEXT category TAG price NUMERIC" \ "Creating search index 'books'" # Test 2: Add documents to the index execute_cmd "ft.add books book1 1.0 title \"The Great Gatsby\" description \"A classic American novel about the Jazz Age\" author \"F. Scott Fitzgerald\" category \"fiction,classic\" price \"12.99\"" \ "Adding first book" execute_cmd "ft.add books book2 1.0 title \"To Kill a Mockingbird\" description \"A novel about racial injustice in the American South\" author \"Harper Lee\" category \"fiction,classic\" price \"14.99\"" \ "Adding second book" execute_cmd "ft.add books book3 1.0 title \"Programming Rust\" description \"A comprehensive guide to Rust programming language\" author \"Jim Blandy\" category \"programming,technical\" price \"49.99\"" \ "Adding third book" execute_cmd "ft.add books book4 1.0 title \"The Rust Programming Language\" description \"The official book on Rust programming\" author \"Steve Klabnik\" category \"programming,technical\" price \"39.99\"" \ "Adding fourth book" # Test 3: Basic search execute_cmd "ft.search books Rust" \ "Searching for 'Rust'" # Test 4: Search with filters execute_cmd "ft.search books programming FILTER category programming" \ "Searching for 'programming' with category filter" # Test 5: Search with limit execute_cmd "ft.search books \"*\" LIMIT 0 2" \ "Getting first 2 documents" # Test 6: Get index info execute_cmd "ft.info books" \ "Getting index information" # Test 7: Delete a document execute_cmd "ft.del books book1" \ "Deleting book1" # Test 8: Search again to verify deletion execute_cmd "ft.search books Gatsby" \ "Searching for deleted book" # Test 9: Drop the index execute_cmd "ft.drop books" \ "Dropping the index" echo "๐ŸŽ‰ All tests completed successfully!" echo "โœ… Tantivy search integration is working correctly"