同时进行大量插入操作时,可能会返回包含缺失匹配项的 HTTP 200 搜索结果
BASE = "http://127.0.0.1:18108" HEADERS = {"X-TYPESENSE-API-KEY": "xyz"} PER_PAGE = 250 bad_seen = threading.Event() bad_lock = threading.Lock() first_bad = {}
def request(method, path, body=None, content_type="application/json"): headers = dict(HEADERS) data = None if body is not None: headers["Content-Type"] = content_type data = body.encode() req = urllib.request.Request(BASE + path, data=data, headers=headers, method=method) with urllib.request.urlopen(req, timeout=120) as response: return response.status, response.read().decode()
schema = { "name": "products", "fields": [ {"name": "name", "type": "string"}, {"name": "created_at", "type": "int64", "sort": True}, {"name": "payload", "type": "string", "index": False}, ], "default_sorting_field": "created_at", } request("POST", "/collections", json.dumps(schema))
params = urllib.parse.urlencode({ "q": "*", "query_by": "name", "sort_by": "created_at:desc", "per_page": PER_PAGE, "include_fields": "id,name,created_at", "use_cache": "false", }) search_path = "/collections/products/documents/search?" + params
内容来源: typesense/typesense