aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/default_settings.py2
-rw-r--r--wqflask/wqflask/database.py19
2 files changed, 21 insertions, 0 deletions
diff --git a/etc/default_settings.py b/etc/default_settings.py
index 6d7ac063..ab5a06cf 100644
--- a/etc/default_settings.py
+++ b/etc/default_settings.py
@@ -35,6 +35,8 @@ GN2_PROXY = "http://localhost:8080"
# GN PROXY
GN_PROXY_URL="https://genenetwork.org/gn3-proxy/"
+# Xapian index
+XAPIAN_DB_PATH = "xapian"
# ---- MySQL
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py
index 505f4bd2..d392f1d1 100644
--- a/wqflask/wqflask/database.py
+++ b/wqflask/wqflask/database.py
@@ -8,6 +8,7 @@ import contextlib
#: type: ignore
import MySQLdb
+import xapian
class Connection(Protocol):
@@ -65,3 +66,21 @@ def database_connection() -> Iterator[Connection]:
connection.commit()
finally:
connection.close()
+
+
+@contextlib.contextmanager
+def xapian_database():
+ """Open xapian database read-only."""
+ # pylint: disable-next=invalid-name
+ db = xapian.Database(get_setting("XAPIAN_DB_PATH"))
+ yield db
+ db.close()
+
+
+@contextlib.contextmanager
+def xapian_writable_database():
+ """Open xapian database for writing."""
+ # pylint: disable-next=invalid-name
+ db = xapian.WritableDatabase(get_setting("XAPIAN_DB_PATH"))
+ yield db
+ db.close()