0

I have a View that uses "Search Terms" to search nodes of the content type "Products". I added a new taxonomy term field to the Product nodes, and then added that field to the View. When I use the View to search for a taxonomy term, though, the it is not returning the nodes that have that term.

Is there a better way to handle this search or something obvious that I am doing wrong?

Here is the code for the view:

$view = new view();
$view->name = 'search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Search';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Search';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Global: Unfiltered text */
$handler->display->display_options['empty']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['table'] = 'views';
$handler->display->display_options['empty']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['empty']['area_text_custom']['content'] = '<h3>Sorry, no results found. Please modify your search.</h3>';
/* Field: Content: Image */
$handler->display->display_options['fields']['field_image_cache']['id'] = 'field_image_cache';
$handler->display->display_options['fields']['field_image_cache']['table'] = 'field_data_field_image_cache';
$handler->display->display_options['fields']['field_image_cache']['field'] = 'field_image_cache';
$handler->display->display_options['fields']['field_image_cache']['label'] = '';
$handler->display->display_options['fields']['field_image_cache']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_image_cache']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_image_cache']['settings'] = array(
  'image_style' => 'thumbnail',
  'image_link' => 'content',
);
$handler->display->display_options['fields']['field_image_cache']['delta_limit'] = '1';
$handler->display->display_options['fields']['field_image_cache']['delta_offset'] = '0';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Product: SKU */
$handler->display->display_options['fields']['model']['id'] = 'model';
$handler->display->display_options['fields']['model']['table'] = 'uc_products';
$handler->display->display_options['fields']['model']['field'] = 'model';
$handler->display->display_options['fields']['model']['label'] = '';
$handler->display->display_options['fields']['model']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['model']['alter']['text'] = '~ [model] ';
$handler->display->display_options['fields']['model']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['model']['link_to_node'] = TRUE;
/* Field: Field: Description */
$handler->display->display_options['fields']['field_description']['id'] = 'field_description';
$handler->display->display_options['fields']['field_description']['table'] = 'field_data_field_description';
$handler->display->display_options['fields']['field_description']['field'] = 'field_description';
$handler->display->display_options['fields']['field_description']['label'] = '';
$handler->display->display_options['fields']['field_description']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_description']['alter']['text'] = '[field_description]';
$handler->display->display_options['fields']['field_description']['alter']['max_length'] = '150';
$handler->display->display_options['fields']['field_description']['alter']['trim'] = TRUE;
$handler->display->display_options['fields']['field_description']['element_label_colon'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['exclude'] = TRUE;
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['alter']['text'] = 'View Details';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing']['alter']['path'] = '/node/[nid]/view';
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
/* Field: Content: All taxonomy terms */
$handler->display->display_options['fields']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['fields']['term_node_tid']['table'] = 'node';
$handler->display->display_options['fields']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['fields']['term_node_tid']['label'] = '';
$handler->display->display_options['fields']['term_node_tid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['term_node_tid']['type'] = 'ul';
$handler->display->display_options['fields']['term_node_tid']['link_to_taxonomy'] = FALSE;
$handler->display->display_options['fields']['term_node_tid']['limit'] = TRUE;
$handler->display->display_options['fields']['term_node_tid']['vocabularies'] = array(
  'product_tags' => 'product_tags',
  'blog_categories' => 0,
  'catalog' => 0,
  'vocabulary_2' => 0,
);
/* Field: Content: Product Tags */
$handler->display->display_options['fields']['field_product_tags']['id'] = 'field_product_tags';
$handler->display->display_options['fields']['field_product_tags']['table'] = 'field_data_field_product_tags';
$handler->display->display_options['fields']['field_product_tags']['field'] = 'field_product_tags';
$handler->display->display_options['fields']['field_product_tags']['label'] = '';
$handler->display->display_options['fields']['field_product_tags']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_product_tags']['type'] = 'taxonomy_term_reference_plain';
$handler->display->display_options['fields']['field_product_tags']['delta_offset'] = '0';
/* Sort criterion: Search: Score */
$handler->display->display_options['sorts']['score']['id'] = 'score';
$handler->display->display_options['sorts']['score']['table'] = 'search_index';
$handler->display->display_options['sorts']['score']['field'] = 'score';
$handler->display->display_options['sorts']['score']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Node: Is a product */
$handler->display->display_options['filters']['is_product']['id'] = 'is_product';
$handler->display->display_options['filters']['is_product']['table'] = 'uc_products';
$handler->display->display_options['filters']['is_product']['field'] = 'is_product';
$handler->display->display_options['filters']['is_product']['value'] = '1';
$handler->display->display_options['filters']['is_product']['group'] = 1;
/* Filter criterion: Search: Search Terms */
$handler->display->display_options['filters']['keys']['id'] = 'keys';
$handler->display->display_options['filters']['keys']['table'] = 'search_index';
$handler->display->display_options['filters']['keys']['field'] = 'keys';
$handler->display->display_options['filters']['keys']['group'] = 1;
$handler->display->display_options['filters']['keys']['exposed'] = TRUE;
$handler->display->display_options['filters']['keys']['expose']['operator_id'] = 'keys_op';
$handler->display->display_options['filters']['keys']['expose']['label'] = 'Search Terms';
$handler->display->display_options['filters']['keys']['expose']['operator'] = 'keys_op';
$handler->display->display_options['filters']['keys']['expose']['identifier'] = 'keys';
$handler->display->display_options['filters']['keys']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  9 => 0,
  8 => 0,
  3 => 0,
  7 => 0,
  6 => 0,
  4 => 0,
  5 => 0,
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'product-search';
0

The "Search terms" field isn't related to Taxonomy terms, it just denotes phrases you might enter into some search field and it searches through the indexed content. It isn't used so often unless you need generic keyword search.

If you want to add a Taxonomy term filter, try adding the Content: Has taxonomy term Filter and Expose it so users can choose terms directly. Choose Dropdown to see all the terms listed in the Exposed form instead of an autocomplete field where users have to type in the term themselves.

The module Better Exposed Filters can help you change the look of the Exposed filter form to see checkboxes next to terms instead of a list.

If you want to learn more about the "Search term" Filter try reading here: How To Create Search Pages Using Views In Drupal 7 although that's probably not what you're after.

BTW although views details show everything seeing a screenshot of the Views configuration is much easier and faster to read ;)

  • Thanks. The issue I am hitting is that I want users to simultaneously search by both taxonomy terms and by the search terms. I do have taxonomy terms exposed to be indexed. The search terms, including tax terms, is up and working on a dev site but I am having trouble getting it to work on the live site. Is there a way to set up views to simultaneously search both? – Kimberlie Davis Jun 6 at 22:33
  • If everything is working locally why not just repeat it on the live site? If you want to search two fields at once you can use the Combine fields filter, you can learn more here: Search multiple Drupal Fields at the same time—Combine fields filter – prkos Jun 6 at 23:15
  • I tried repeating it on the live site, but cannot get it to work there for some reason. Obviously I'm missing something, but I can't find what. I also tried combine fields filter but it is throwing a "Column not found: 1054 Unknown column 'node.term_node_tid' in 'where clause'" error. – Kimberlie Davis Jun 6 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.