import requests

BASE_URL = "http://localhost:8000"
INDEX = "myindex"

# ドキュメントを登録
def add_document(content, metadata=None):
    resp = requests.post(
        f"{BASE_URL}/{INDEX}/",
        json={"content": content, "metadata": metadata or {}}
    )
    return resp.json()

# 全文検索
def search(query, page=1):
    resp = requests.get(
        f"{BASE_URL}/{INDEX}/",
        params={"q": query, "page": page}
    )
    return resp.json()

# 使用例
add_document("Scout is a lightweight search server.", {"author": "alice", "tag": "intro"})
add_document("SQLite FTS5 provides fast full-text search.", {"author": "bob", "tag": "db"})

results = search("lightweight")
for doc in results["documents"]:
    print(f"[{doc['id']}] score={doc.get('score', 'N/A'):.4f}: {doc['content'][:60]}")