From 0ab1958235907729c595cef42c22e78c8e8363b0 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 22 Aug 2024 18:11:00 +0100 Subject: [PATCH] work on query engine --- jamesql/index.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jamesql/index.py b/jamesql/index.py index 8efb951..91bb5b8 100644 --- a/jamesql/index.py +++ b/jamesql/index.py @@ -85,7 +85,7 @@ def _close_to(self, query: list) -> dict: stride_range = range(-stride, stride + 1) - if gsi["strategy"] == GSI_INDEX_STRATEGIES.CONTAINS: + if gsi["strategy"] == GSI_INDEX_STRATEGIES.CONTAINS.name: for doc_id, positions in current_word_positions.items(): if doc_id not in previous_word_positions: continue @@ -179,9 +179,9 @@ def add(self, document: list, doc_id=None) -> Dict[str, dict]: if doc_id: document["uuid"] = doc_id else: - doc_uuid = uuid.uuid4().hex + document["uuid"] = uuid.uuid4().hex - self.global_index[doc_uuid] = document + self.global_index[document["uuid"]] = document self.uuids_to_position_in_global_index[document["uuid"]] = ( len(self.global_index) - 1 @@ -263,7 +263,7 @@ def create_gsi( + "." ) - self.gsis[index_by] = {"gsi": gsi, "strategy": strategy} + self.gsis[index_by] = {"gsi": gsi, "strategy": strategy.name} return gsi @@ -445,7 +445,8 @@ def _run(self, query: dict, query_field: str) -> List[str]: if not self.gsis.get(query_field): self.create_gsi(query_field, GSI_INDEX_STRATEGIES.FLAT) - gsi_type = self.gsis[query_field]["strategy"] + gsi_type = GSI_INDEX_STRATEGIES[self.gsis[query_field]["strategy"]] + gsi = self.gsis[query_field]["gsi"] fuzzy = query["query"][query_field].get("fuzzy", False)