diff options
author | Arun Isaac | 2022-10-28 16:47:30 +0530 |
---|---|---|
committer | Arun Isaac | 2022-10-28 16:57:30 +0530 |
commit | faf2739d30decda1e0ba46699ebec776ef7d3e0d (patch) | |
tree | 89541bc760121a0b2e696894adf2d467cd59c092 | |
parent | d36d2faaceff255983a2baa5ef982936d2f4a6ae (diff) | |
download | genenetwork3-faf2739d30decda1e0ba46699ebec776ef7d3e0d.tar.gz |
Use Xapian index path from app settings.
App settings should be accessed from current_app. It should not be hard-coded
to a variable in a module.
* gn3/db_utils.py: Do not import XAPIAN_DB_PATH from gn3.settings.
(xapian_database): Accept path argument.
* gn3/api/search.py: Import current_app from flask.
(search_results): Pass Xapian index path to xapian_database.
-rw-r--r-- | gn3/api/search.py | 4 | ||||
-rw-r--r-- | gn3/db_utils.py | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py index 78a3245..f4d0aeb 100644 --- a/gn3/api/search.py +++ b/gn3/api/search.py @@ -3,7 +3,7 @@ import json import urllib.parse -from flask import abort, Blueprint, jsonify, request +from flask import abort, Blueprint, current_app, jsonify, request import xapian from gn3.monads import MonadicDict @@ -42,7 +42,7 @@ def search_results(): query = queryparser.parse_query(querystring) traits = [] # pylint: disable=invalid-name - with xapian_database() as db: + with xapian_database(current_app.config["XAPIAN_DB_PATH"]) as db: enquire = xapian.Enquire(db) # Filter documents by type. enquire.set_query(xapian.Query(xapian.Query.OP_FILTER, diff --git a/gn3/db_utils.py b/gn3/db_utils.py index af1024a..4fd3666 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -4,7 +4,7 @@ from typing import Any, Iterator, Protocol, Tuple from urllib.parse import urlparse import MySQLdb as mdb import xapian -from gn3.settings import SQL_URI, XAPIAN_DB_PATH +from gn3.settings import SQL_URI def parse_db_url() -> Tuple: @@ -47,10 +47,10 @@ def database_connection() -> Iterator[Connection]: @contextlib.contextmanager -def xapian_database(): +def xapian_database(path): """Open xapian database read-only.""" # pylint: disable-next=invalid-name - db = xapian.Database(XAPIAN_DB_PATH) + db = xapian.Database(path) try: yield db finally: |