Fix Neo4J index creation to check state instead of analyzer
• Check index state not analyzer • Skip if index is ONLINE • Recreate if state not ONLINE • Simplify recreation logic
This commit is contained in:
parent
9e0dabc34d
commit
040b0c8620
1 changed files with 22 additions and 15 deletions
|
|
@ -246,28 +246,35 @@ class Neo4JStorage(BaseGraphStorage):
|
||||||
existing_index = idx
|
existing_index = idx
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check if we need to recreate the index
|
# Check if index exists and is online
|
||||||
needs_recreation = False
|
|
||||||
if existing_index:
|
if existing_index:
|
||||||
# Check if the existing index has CJK analyzer
|
index_state = existing_index.get("state", "UNKNOWN")
|
||||||
index_config = existing_index.get("options", {})
|
logger.info(
|
||||||
current_analyzer = index_config.get("indexConfig", {}).get(
|
f"[{self.workspace}] Found existing index '{index_name}' with state: {index_state}"
|
||||||
"fulltext.analyzer", "standard"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if current_analyzer != "cjk":
|
if index_state == "ONLINE":
|
||||||
logger.info(
|
logger.info(
|
||||||
f"[{self.workspace}] Existing index '{index_name}' uses '{current_analyzer}' analyzer. "
|
f"[{self.workspace}] Full-text index '{index_name}' already exists and is online. Skipping recreation."
|
||||||
"Recreating with CJK analyzer for Chinese support."
|
|
||||||
)
|
|
||||||
needs_recreation = True
|
|
||||||
else:
|
|
||||||
logger.debug(
|
|
||||||
f"[{self.workspace}] Full-text index '{index_name}' already exists with CJK analyzer."
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
f"[{self.workspace}] Existing index '{index_name}' is not online (state: {index_state}). Will recreate."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
f"[{self.workspace}] No existing index '{index_name}' found. Creating new index."
|
||||||
|
)
|
||||||
|
|
||||||
if not existing_index or needs_recreation:
|
# Create or recreate the index if needed
|
||||||
|
needs_recreation = (
|
||||||
|
existing_index is not None
|
||||||
|
and existing_index.get("state") != "ONLINE"
|
||||||
|
)
|
||||||
|
needs_creation = existing_index is None
|
||||||
|
|
||||||
|
if needs_recreation or needs_creation:
|
||||||
# Drop existing index if it needs recreation
|
# Drop existing index if it needs recreation
|
||||||
if needs_recreation:
|
if needs_recreation:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue