欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal 自定义字段 field 能够被 apache solr 搜索到 的思路 有大用 有大大用 有大大大用

要先看看 /node-admin/17181   因为与 17181 基本相同

然后 自定义字段 与  17181 不同之处为


1)   17181的第5)步 

image.png

2) 17181的第6)步

 自定义字段是 field_done

function custom_one_apachesolr_query_prepare($query) {
   
$query->addParam('fl', 'sm_field_done');
//   $query->addParam('fl', 'ts_field_done'); // 若是ts_field_done,则设成 $query->addParam('qf', 'ts_field_done'); 切记,这里是 qf ,不是 fq
//   $query->addParam('qf', 'teaser');
}

// 这个函数可以不要 ,一般不需要addField SS_ 开头 ,因为默认情况下 是有 sm_field_done 的,见上图 ,
function custom_one_apachesolr_index_document_build_node(ApacheSolrDocument $document, $entity, $env_id) {
   
//$entity_type 为 solr
   
if ( $entity->type == 'to_do') {
       
if($fields = field_get_items('node',$entity,'field_done')){
           
$value = field_view_value('node',$entity,'field_done',$fields[0]);
           
$document->addField('ss_field_done', $value); //或者设成 ts_field_done,, ss_开头表示 string single(单值), ts_ 开头 表示 text single(单值)
       }
   }
}





即使设了之后, 

在 /admin/config/search/apachesolr/settings/solr/index 页面重建索引,后

,image.png

看到的 http://192.168.46.127:8983/solr/#/drupal  索引的内容为空

image.png


3) 下面这个页面好像不需要设置

/admin/config/search/apachesolr/settings/solr/facets?destination=admin/config/search/apachesolr/settings

image.png

普通分类: