Handle none for search_type and use equals comparator rather than in for determining Notion type

This commit is contained in:
sabaimran
2023-11-21 12:55:09 -08:00
parent 19e042037a
commit 341abf03ff

View File

@@ -1,40 +1,25 @@
# Standard Packages
import logging
from typing import Optional, Union, Dict
import asyncio import asyncio
import logging
from typing import Dict, Optional, Union
# External Packages
from fastapi import APIRouter, Header, Request, Response, UploadFile from fastapi import APIRouter, Header, Request, Response, UploadFile
from pydantic import BaseModel from pydantic import BaseModel
from starlette.authentication import requires from starlette.authentication import requires
# Internal Packages from khoj.database.models import GithubConfig, KhojUser, NotionConfig
from khoj.utils import state, constants from khoj.processor.github.github_to_entries import GithubToEntries
from khoj.processor.markdown.markdown_to_entries import MarkdownToEntries from khoj.processor.markdown.markdown_to_entries import MarkdownToEntries
from khoj.processor.notion.notion_to_entries import NotionToEntries
from khoj.processor.org_mode.org_to_entries import OrgToEntries from khoj.processor.org_mode.org_to_entries import OrgToEntries
from khoj.processor.pdf.pdf_to_entries import PdfToEntries from khoj.processor.pdf.pdf_to_entries import PdfToEntries
from khoj.processor.github.github_to_entries import GithubToEntries
from khoj.processor.notion.notion_to_entries import NotionToEntries
from khoj.processor.plaintext.plaintext_to_entries import PlaintextToEntries from khoj.processor.plaintext.plaintext_to_entries import PlaintextToEntries
from khoj.search_type import text_search, image_search
from khoj.routers.helpers import update_telemetry_state from khoj.routers.helpers import update_telemetry_state
from khoj.utils.yaml import save_config_to_file_updated_state from khoj.search_type import image_search, text_search
from khoj.utils.config import SearchModels from khoj.utils import constants, state
from khoj.utils.config import ContentIndex, SearchModels
from khoj.utils.helpers import LRU, get_file_type from khoj.utils.helpers import LRU, get_file_type
from khoj.utils.rawconfig import ( from khoj.utils.rawconfig import ContentConfig, FullConfig, SearchConfig
ContentConfig, from khoj.utils.yaml import save_config_to_file_updated_state
FullConfig,
SearchConfig,
)
from khoj.utils.config import (
ContentIndex,
SearchModels,
)
from khoj.database.models import (
KhojUser,
GithubConfig,
NotionConfig,
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -189,6 +174,9 @@ def configure_content(
content_index = ContentIndex() content_index = ContentIndex()
success = True success = True
if t == None:
t = state.SearchType.All
if t is not None and t in [type.value for type in state.SearchType]: if t is not None and t in [type.value for type in state.SearchType]:
t = state.SearchType(t) t = state.SearchType(t)
@@ -315,7 +303,7 @@ def configure_content(
# Initialize Notion Search # Initialize Notion Search
notion_config = NotionConfig.objects.filter(user=user).first() notion_config = NotionConfig.objects.filter(user=user).first()
if ( if (
search_type == state.SearchType.All.value or search_type in state.SearchType.Notion.value search_type == state.SearchType.All.value or search_type == state.SearchType.Notion.value
) and notion_config: ) and notion_config:
logger.info("🔌 Setting up search for notion") logger.info("🔌 Setting up search for notion")
text_search.setup( text_search.setup(
@@ -328,7 +316,7 @@ def configure_content(
) )
except Exception as e: except Exception as e:
logger.error(f"🚨 Failed to setup GitHub: {e}", exc_info=True) logger.error(f"🚨 Failed to setup Notion: {e}", exc_info=True)
success = False success = False
# Invalidate Query Cache # Invalidate Query Cache