I have a simple view that uses an autocomplete 'Taxonomy:Term' filter to show a list of nodes that have been tagged with that taxonomy term. It usually works ok, but for some terms it would return no results.
The problem happens when the term exists in more than one vocabulary. Then the SQL query that is generated searches for nodes that have the term in all vocabularies, and of course there are none.
I've used the 'cog' icon to set the 'Vocabulary:' to the correct vocabulary, so that isn't the problem.
If I change the exposed filter's 'Selection type:' to Dropdown, then the SQL query is correct, and the correct list of nodes is returned and displayed.
I am using Drupal 6.8.
I attach the two versions below.
First here's the exported view that fails, using the Autocomplete:
$view = new view;
$view->name = 'place_list_search';
$view->description = 'All places on list, searchable by tags';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'name' => array(
'label' => 'Tags:',
'link_to_taxonomy' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'term_data',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'place' => 'place',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'tid' => array(
'operator' => 'and',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'operator' => 'tid_op',
'label' => 'Tags',
'use_operator' => 0,
'identifier' => 'tid',
'optional' => 1,
'single' => 0,
'remember' => 0,
),
'type' => 'textfield',
'vid' => '2',
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('title', 'List of Hong Kong Places');
$handler->override_option('header', 'Type in a tag below (eg <em>pub</em>, or <em>beach</em>) and click \'Apply\' to see all the places with that tag.');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('footer', 'To use the map:<ul><li>Each red marker is a place in Hong Kong. Hold your mouse over a marker to see the place\'s name, or click the marker to see the place in detail.</li>
<li>Click the \'+\' or \'-\' buttons to zoom in or out</li>
<li>Click and drag the map to move it</li>
<li>Click the \'Map\', \'Satellite\', or \'Hybrid\' buttons to change the view</li>
</ul>');
$handler->override_option('footer_format', '1');
$handler->override_option('footer_empty', 0);
$handler->override_option('empty', 'No matching places found - please try another tag.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ol',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'place-list-search');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
And here's the problem SQL that it generates:
SELECT node.nid AS nid,
node.title AS node_title,
term_data.name AS term_data_name,
term_data.vid AS term_data_vid,
term_data.tid AS term_data_tid
FROM node node
INNER JOIN term_node term_node_value_0 ON node.vid = term_node_value_0.vid AND term_node_value_0.tid = 81
INNER JOIN term_node term_node_value_1 ON node.vid = term_node_value_1.vid AND term_node_value_1.tid = 82
LEFT JOIN term_data term_data ON term_node_value_0.tid = term_data.tid
WHERE (node.type in ('place')) AND (term_node_value_0.tid = 81 AND term_node_value_1.tid = 82)
Next there's the exported view that works, using the Dropdown:
$view = new view;
$view->name = 'place_list_search';
$view->description = 'All places on list, searchable by tags';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'name' => array(
'label' => 'Tags:',
'link_to_taxonomy' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'term_data',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'place' => 'place',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'tid' => array(
'operator' => 'and',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'operator' => 'tid_op',
'label' => 'Tags',
'use_operator' => 0,
'identifier' => 'tid',
'optional' => 1,
'single' => 0,
'remember' => 0,
),
'type' => 'select',
'vid' => '2',
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('title', 'List of Hong Kong Places');
$handler->override_option('header', 'Type in a tag below (eg <em>pub</em>, or <em>beach</em>) and click \'Apply\' to see all the places with that tag.');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('footer', 'To use the map:<ul><li>Each red marker is a place in Hong Kong. Hold your mouse over a marker to see the place\'s name, or click the marker to see the place in detail.</li>
<li>Click the \'+\' or \'-\' buttons to zoom in or out</li>
<li>Click and drag the map to move it</li>
<li>Click the \'Map\', \'Satellite\', or \'Hybrid\' buttons to change the view</li>
</ul>');
$handler->override_option('footer_format', '1');
$handler->override_option('footer_empty', 0);
$handler->override_option('empty', 'No matching places found - please try another tag.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ol',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'place-list-search');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
And correct SQL that it generates:
SELECT node.nid AS nid,
node.title AS node_title,
term_data.name AS term_data_name,
term_data.vid AS term_data_vid,
term_data.tid AS term_data_tid
FROM node node
INNER JOIN term_node term_node_value_0 ON node.vid = term_node_value_0.vid AND term_node_value_0.tid = 82
LEFT JOIN term_data term_data ON term_node_value_0.tid = term_data.tid
WHERE (node.type in ('place')) AND (term_node_value_0.tid = 82)
Comments
Comment #1
merlinofchaos commentedOk, figured this one out. Fixed in CVS, will be in 2.3