Skip to content

Commit

Permalink
update connection class
Browse files Browse the repository at this point in the history
  • Loading branch information
rbs333 committed Jan 21, 2025
1 parent 14c1947 commit 6c457ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 7 additions & 8 deletions backend/arxivsearch/db/redis_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@
import os
from typing import List

from arxivsearch import config
from redis.asyncio import Redis
from redisvl.index import AsyncSearchIndex, SearchIndex
from redisvl.query.filter import FilterExpression, Tag
from redisvl.schema import IndexSchema

from arxivsearch import config

logger = logging.getLogger(__name__)


dir_path = os.path.dirname(os.path.realpath(__file__))
schema = IndexSchema.from_yaml(os.path.join(dir_path, "index.yaml"))
schema_path = os.path.join(dir_path, "index.yaml")
schema = IndexSchema.from_yaml(schema_path)
client = Redis.from_url(config.REDIS_URL)
global_index = None


def get_schema():
dir_path = os.path.dirname(os.path.realpath(__file__))
return IndexSchema.from_yaml(os.path.join(dir_path, "index.yaml"))
return IndexSchema.from_yaml(schema_path)


def get_test_index():
dir_path = os.path.dirname(os.path.realpath(__file__))
index = SearchIndex.from_yaml(os.path.join(dir_path, "index.yaml"))
index = SearchIndex.from_yaml(schema_path)
index.connect(redis_url=config.REDIS_URL)

if not index.exists():
Expand All @@ -37,7 +35,8 @@ def get_test_index():
async def get_async_index():
global global_index
if not global_index:
global_index = AsyncSearchIndex(schema, client)
global_index = AsyncSearchIndex.from_yaml(schema_path)
await global_index.set_client(client)
yield global_index


Expand Down
9 changes: 5 additions & 4 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ isort = ">=5.6.4"
pytest-cov = "5.0.0"
pytest-asyncio = "^0.23.7"
pytest = "^8.2.2"
httpx = "0.27.2"
types-redis = "*"
types-pyyaml = "*"
types-tabulate = "*"
Expand Down

0 comments on commit 6c457ea

Please sign in to comment.