From 49b5ac7bec25254339e5fa9d1de0ce6d5b3d9f08 Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Mon, 6 Nov 2023 17:00:13 -0500 Subject: [PATCH] Don't import django.contrib.postgres.search if not using postgresql. Importing django.contrib.postgres.search requires having psycopg2 installed, which often requires compiling psycopg2 from source, which can be a nuisance. Remove this hard dependency (only import the module if the relevant backend is being used) so that it's possible to run a demo server using sqlite without having psycopg2 installed. --- physionet-django/search/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/physionet-django/search/views.py b/physionet-django/search/views.py index de990710b3..ab5f17126a 100644 --- a/physionet-django/search/views.py +++ b/physionet-django/search/views.py @@ -4,7 +4,6 @@ from functools import reduce from django.conf import settings -from django.contrib.postgres.search import SearchQuery, SearchVector, SearchRank from django.db.models import Case, Count, IntegerField, Q, Sum, Value, When from django.http import Http404 from django.shortcuts import redirect, render, reverse @@ -63,6 +62,11 @@ def get_content(resource_type, orderby, direction, search_term): def get_content_postgres_full_text_search(resource_type, orderby, direction, search_term): + from django.contrib.postgres.search import ( + SearchQuery, + SearchRank, + SearchVector, + ) # Split search term by whitespace or punctuation if search_term: