-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search_api.py
More file actions
68 lines (58 loc) · 1.92 KB
/
Copy pathtest_search_api.py
File metadata and controls
68 lines (58 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""
Quick test of the grepctl Search API.
"""
from grepctl import SearchClient, search
def test_basic_api():
"""Test basic Search API functionality."""
print("Testing grepctl Search API")
print("=" * 50)
# Test 1: Create client
print("\n1. Creating SearchClient...")
try:
client = SearchClient()
print(" ✅ Client created successfully")
except Exception as e:
print(f" ❌ Error: {e}")
return
# Test 2: Get stats
print("\n2. Getting system statistics...")
try:
stats = client.get_stats()
print(f" ✅ Documents indexed: {stats['document_count']:,}")
print(f" ✅ Dataset: {stats['dataset_name']}")
except Exception as e:
print(f" ❌ Error: {e}")
# Test 3: Simple search
print("\n3. Testing simple search...")
try:
results = client.search_simple("test", limit=2)
print(f" ✅ Found {len(results)} results")
if results:
print(f" Preview: {results[0][:100]}...")
except Exception as e:
print(f" ❌ Error: {e}")
# Test 4: Full search
print("\n4. Testing full search with filters...")
try:
results = client.search(
query="data",
top_k=3,
sources=["text", "markdown"],
)
print(f" ✅ Found {len(results)} results")
for i, r in enumerate(results, 1):
print(f" {i}. Score: {r['score']:.3f} | Source: {r['source']}")
except Exception as e:
print(f" ❌ Error: {e}")
# Test 5: Quick search function
print("\n5. Testing quick search function...")
try:
results = search("python", top_k=2)
print(f" ✅ Quick search found {len(results)} results")
except Exception as e:
print(f" ❌ Error: {e}")
print("\n" + "=" * 50)
print("✅ All tests completed!")
if __name__ == "__main__":
test_basic_api()