Skip to content

Commit

Permalink
Don't import django.contrib.postgres.search if not using postgresql.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Benjamin Moody committed Nov 6, 2023
1 parent b610b12 commit 49b5ac7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion physionet-django/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 49b5ac7

Please sign in to comment.