fgdfg 发表于 2017-12-19 20:40:03

solr联合多个字段进行检索(multivalued和copyfield的使用)

  copyField与multiValued用途
  在我们的应用中经常会有这种情形:当用户输入某个字符串查找时,需要如果在标题及内容中存在这个字会串时均要把记录加载出来,通过引入copyField及multiValue这两个标签便可解决这种问题。如:
  

<!--这里无需定义id,因为managed_schema文件已经在前面开头位置定义了,id是必须,并且唯一的-->  
<field name="S_user" type="string" indexed="true" stored="true"/>
  
<field name="S_text" type="string" indexed="true" stored="true"/>
  
<field name="sgk" type="string" indexed="true" stored="false" multiValued="true"/>
  
<!--CopyField复制域,功能就是在添加文档的时候自动的把源域的内容复制到目标域。可以把目标域作为默认搜索域可以提高查询的性能。
  
Source:源域
  
Dest:目标域-->
  
<copyField source="S_user" dest="sgk" />
  
<copyField source="S_text" dest="sgk" />
  


  1.首先也要定义目标域的属性,name域名=sgk,type类型,indexed是否索引,stored是否存储(不存储,这里只到连接的作用),multiValued=true
  

<copyField source="S_user" dest="sgk" />  
<copyField source="S_text" dest="sgk" />
  把S_user和S_text用sgk联合和进行检索
  


  从上图看出sgk区域,是s_user、s_texte 两个的集合,无论搜索s_user、s_texte 中任意一个,都能通过sgk搜索出来
  
页: [1]
查看完整版本: solr联合多个字段进行检索(multivalued和copyfield的使用)