diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 9110b87b..635ee65c 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -2,7 +2,7 @@ from functools import reduce import operator -from django.contrib.postgres.search import SearchRank +from django.contrib.postgres.search import SearchRank, SearchQuery from django.db.models import OuterRef, Subquery, F, Q from bookwyrm import models @@ -141,6 +141,7 @@ def search_identifiers(query, *filters): def search_title_author(query, min_confidence, *filters): """searches for title and author""" + query = SearchQuery(query, config="simple") | SearchQuery(query, config="english") results = ( models.Edition.objects.annotate(rank=SearchRank("search_vector", query)) .filter(*filters, search_vector=query, rank__gt=min_confidence) diff --git a/bookwyrm/migrations/0077_auto_20210623_2155.py b/bookwyrm/migrations/0077_auto_20210623_2155.py index 4773e6bd..d72f8363 100644 --- a/bookwyrm/migrations/0077_auto_20210623_2155.py +++ b/bookwyrm/migrations/0077_auto_20210623_2155.py @@ -39,17 +39,20 @@ class Migration(migrations.Migration): CREATE FUNCTION book_trigger() RETURNS trigger AS $$ begin new.search_vector := - setweight(to_tsvector('pg_catalog.english', coalesce(new.title, '')), 'A') || - setweight(to_tsvector('pg_catalog.english', coalesce(new.subtitle, '')), 'B') || - setweight(to_tsvector('pg_catalog.english', coalesce(new.series, '')), 'D') || - (SELECT setweight(to_tsvector('simple', coalesce(array_to_string(array_agg(bookwyrm_author.name), ' '), '')), 'C') + coalesce( + NULLIF(setweight(to_tsvector('english', coalesce(new.title, '')), 'A'), ''), + setweight(to_tsvector('simple', coalesce(new.title, '')), 'A') + ) || + setweight(to_tsvector('english', coalesce(new.subtitle, '')), 'B') || + (SELECT setweight(to_tsvector('simple', coalesce(array_to_string(array_agg(bookwyrm_author.name), ' '), '')), 'B') FROM bookwyrm_book LEFT OUTER JOIN bookwyrm_book_authors ON bookwyrm_book.id = bookwyrm_book_authors.book_id LEFT OUTER JOIN bookwyrm_author ON bookwyrm_book_authors.author_id = bookwyrm_author.id WHERE bookwyrm_book.id = new.id - ); + ) || + setweight(to_tsvector('english', coalesce(new.series, '')), 'D'); return new; end $$ LANGUAGE plpgsql;