Views keyword search bug when using node revisions

Created on 22 August 2019, about 5 years ago
Updated 30 March 2023, over 1 year ago

Problem/Motivation

An invalid query is produced on a node revisions view when adding a relationship to the actual content and adding an exposed filter on Search keywords

Steps to reproduce

Install the standard profile on Drupal 10.1.x
Import the attached views config (making sure to rename it to remove the underscore from views.view_
Visit admin/structure/views/view/test_revisions
Submit the filter in the view preview.

Proposed resolution

Original report

A view that is based on node revisions will create an incorrect query if a keyword search filter is included. I've attached the simplest of views from a new drupal 8.7 install to reproduce this. In trying to debug this on a client site I stepped through the search views plugin but it seems like the error in creating table aliases happens earlier which is why I assume the node module.

Here is a base query that works:

SELECT "node_field_revision"."vid" AS "vid", "node_field_data_node_field_revision"."nid" AS "node_field_data_node_field_revision_nid"
FROM
{node_field_revision} "node_field_revision"
LEFT JOIN {node_field_data} "node_field_data_node_field_revision" ON node_field_revision.nid = node_field_data_node_field_revision.nid AND node_field_data_node_field_revision.langcode = node_field_revision.langcode
WHERE "node_field_revision"."status" = '1'

Here's the query that throws an exception when adding a search word of "test":

SELECT SUM(node_field_data_node_field_revision_node_search_index.score * search_total.count) AS "score", MIN(node_field_revision.vid) AS "vid", MIN(node_field_data_node_field_revision.nid) AS "node_field_data_node_field_revision_nid"
FROM
{node_field_revision} "node_field_revision"
LEFT JOIN {node_field_data} "node_field_data_node_field_revision" ON node_field_revision.nid = node_field_data_node_field_revision.nid AND node_field_data_node_field_revision.langcode = node_field_revision.langcode
LEFT JOIN {search_index} "node_field_data_node_field_revision_node_search_index" ON node_field_data_node_field_revision.nid = node_field_data_node_field_revision_node_search_index.sid AND (node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode)
LEFT JOIN {search_total} "search_total" ON node_field_data_node_field_revision_node_search_index.word = search_total.word
WHERE ("node_field_revision"."status" = '1') AND (("node_field_data_node_field_revision_node_search_index"."type" = 'node_search') AND (""."data" LIKE '% test %' ESCAPE '\\') AND ("node_field_data_node_field_revision_node_search_index"."word" = 'test'))
GROUP BY "node_field_data_node_field_revision_node_search_index"."sid"
HAVING (COUNT(*) >= '1')

The '.data' in the third WHERE condition should get replaced by something like 'node_field_data_node_field_revision_node_search_dataset.data' but the search plugin never gets passed any table aliases to use for replacements. line 175 of core/modules/search/src/Plugin/views/filter/Search.php
$search_dataset = $this->query->addTable('node_search_dataset'); returns FALSE:

I was able to alter the query just for my view and that's basically what I had to do. I'm also hoping to figure out where this needs to be patched but I haven't figured that out myself yet.

πŸ› Bug report
Status

Needs review

Version

10.1 ✨

Component
Node systemΒ  β†’

Last updated 1 minute ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States johne

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024