字段集合替代?需要可通过 Search API 搜索的子字段(Drupal 7)
Posted
技术标签:
【中文标题】字段集合替代?需要可通过 Search API 搜索的子字段(Drupal 7)【英文标题】:Field Collection alternative ? Need Sub fields searchable through Search API (Drupal 7) 【发布时间】:2014-03-11 00:12:11 【问题描述】:我希望找到 Field Collection 模块的替代方案。问题是我想搜索(我正在使用 Search API + Views)字段集合中的子字段。
例如,如果我有一个字段集合“字段”,如Research Paper
,具有以下字段:-
我可以在我添加 Research Paper
作为内容类型的页面中添加尽可能多的Research Papers
。
例如,以下是我添加的典型研究论文:-
“植物学”、“寻找可持续的 blah blah.pdf 来源” 《经济学》、《客户支出与天气状况相关性研究.pdf》 “数学”、“在有理数中估计 Pi 级数.pdf”现在问题来了,如果我通过 Search API by a view 创建了一个搜索页面,并搜索“sustainable source of blah blah”,我如何获得“研究论文”的链接` “植物学”、“寻找可持续的 blah blah.pdf 来源”的条目?
我正在使用视图并通过“全文搜索(公开)”进行搜索。
这是视图,以防万一:
$view = new view;
$view->name = 'advanced_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_advanced_search_index';
$view->human_name = 'Advanced 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'] = 'Advanced Search';
$handler->display->display_options['access']['type'] = 'none';
$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['exposed_form']['options']['submit_button'] = 'Search';
$handler->display->display_options['exposed_form']['options']['autosubmit'] = 0;
$handler->display->display_options['exposed_form']['options']['autosubmit_hide'] = 1;
$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';
/* Field: Indexed Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['title']['link_to_entity'] = 1;
/* Field: Indexed Node: The main body text » Summary */
$handler->display->display_options['fields']['body_summary']['id'] = 'body_summary';
$handler->display->display_options['fields']['body_summary']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['body_summary']['field'] = 'body_summary';
$handler->display->display_options['fields']['body_summary']['label'] = '';
$handler->display->display_options['fields']['body_summary']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['external'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['max_length'] = '200';
$handler->display->display_options['fields']['body_summary']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['body_summary']['alter']['trim'] = 1;
$handler->display->display_options['fields']['body_summary']['alter']['html'] = 0;
$handler->display->display_options['fields']['body_summary']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['body_summary']['element_default_classes'] = 1;
$handler->display->display_options['fields']['body_summary']['empty'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vitae est id metus vestibulum mattis. Donec sed dictum sapien. Proin facilisis vehicula elit nec molestie. Nullam scelerisque, urna non venenatis mattis, dolor neque ultricies tellus, quis lacinia mi ligula id risus. Curabitur congue gravida quam. Maecenas et luctus dui. Aliquam erat volutpat ...';
$handler->display->display_options['fields']['body_summary']['hide_empty'] = 0;
$handler->display->display_options['fields']['body_summary']['empty_zero'] = 1;
$handler->display->display_options['fields']['body_summary']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['body_summary']['link_to_entity'] = 0;
/* Field: Document Category » Uploaded File » The file.: Title Text (indexed) */
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['id'] = 'field_document_cat_field_field_document_file_field_file_image_title_text';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['field'] = 'field_document_cat_field_field_document_file_field_file_image_title_text';
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['field_document_cat_field_field_document_file_field_file_image_title_text']['field_api_classes'] = 0;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_advanced_search_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search me';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['use_operator'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['required'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['fields'] = array(
'title' => 'title',
'body:value' => 'body:value',
'field_document_cat_field:field_document:file:name' => 'field_document_cat_field:field_document:file:name',
'field_document_cat_field:field_document:file:field_file_image_title_text' => 'field_document_cat_field:field_document:file:field_file_image_title_text',
);
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'advanced-search';
【问题讨论】:
【参考方案1】:您可以尝试inline_entity_form 或multifield 模块。
相关链接:https://drupal.stackexchange.com/questions/81676/alternative-to-field-collection
【讨论】:
以上是关于字段集合替代?需要可通过 Search API 搜索的子字段(Drupal 7)的主要内容,如果未能解决你的问题,请参考以下文章