Fix authors search

This commit is contained in:
2022-02-06 13:35:08 +03:00
parent d50728d100
commit c759e0edc0
3 changed files with 21 additions and 35 deletions

View File

@@ -17,11 +17,9 @@ SELECT ARRAY(
) as sml,
(
SELECT count(*) FROM book_authors
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE author = authors.id
LEFT JOIN books ON (books.id = book)
WHERE author = authors.id AND books.is_deleted = 'f'
AND books.lang = ANY(:langs ::text[])
) as books_count
FROM authors
WHERE (
@@ -31,11 +29,9 @@ SELECT ARRAY(
) AND
EXISTS (
SELECT * FROM book_authors
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE author = authors.id
LEFT JOIN books ON (books.id = book)
WHERE author = authors.id AND books.is_deleted = 'f'
AND books.lang = ANY(:langs ::text[])
)
)
SELECT fauthors.id FROM filtered_authors as fauthors
@@ -57,11 +53,9 @@ WITH filtered_authors AS (
SELECT id FROM authors
WHERE EXISTS (
SELECT * FROM book_authors
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE author = authors.id
LEFT JOIN books ON (books.id = book)
WHERE author = authors.id AND books.is_deleted = 'f'
AND books.lang = ANY(:langs ::text[])
)
)
SELECT id FROM filtered_authors

View File

@@ -10,21 +10,17 @@ SELECT ARRAY (
similarity(name, :query) as sml,
(
SELECT count(*) FROM book_sequences
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE sequence = sequences.id
LEFT JOIN books ON (books.id = book)
WHERE sequence = sequences.id AND books.is_deleted = 'f'
AND books.lang = ANY(:langs ::text[])
) as books_count
FROM sequences
WHERE name % :query AND
EXISTS (
SELECT * FROM book_sequences
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE sequence = sequences.id
LEFT JOIN books ON (books.id = book)
WHERE sequence = sequences.id AND books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[])
)
)
SELECT fsequences.id FROM filtered_sequences as fsequences

View File

@@ -17,11 +17,9 @@ SELECT ARRAY(
) as sml,
(
SELECT count(*) FROM translations
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE author = authors.id
LEFT JOIN books ON (books.id = book)
WHERE author = authors.id AND books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[])
) as books_count
FROM authors
WHERE (
@@ -31,11 +29,9 @@ SELECT ARRAY(
) AND
EXISTS (
SELECT * FROM translations
LEFT JOIN books
ON (books.id = book AND
books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[]))
WHERE author = authors.id
LEFT JOIN books ON (books.id = book)
WHERE author = authors.id AND books.is_deleted = 'f' AND
books.lang = ANY(:langs ::text[])
)
)
SELECT fauthors.id FROM filtered_authors as fauthors