solr实体嵌套、字段加权查询

创建索引时可能遇到实体嵌套的情况,比如学生信息中包含多个活动。

在solr的data-config.xml中配置:

<entity name="studentProfile" pk="ID"
             query="select CONCAT('studentProfile',studentProfileId) as solr_id,studentProfileId,name,location,description from studentProfile"
             deltaQuery="select sp.studentProfileId as ID  from studentProfile sp,users u where u.registerTime > '${dataimporter.last_index_time}' and sp.email=u.email "   
             deltaImportQuery="select CONCAT('studentProfile',studentProfileId) as solr_id,studentProfileId,name,location,description from studentProfile where studentProfileId='${dataimporter.delta.ID}'"
             >
                <field name="id" column="solr_id"/>
                <field name="studentprofile_id" column="studentProfileId"/>
                <field name="studentprofile_name" column="name"/>
                <field name="studentprofile_location" column="location"/>
                <field name="studentprofile_description" column="description"/>
                <field name="studentprofile_publicUri" column="publicUri"/>

                <entity name="activity"
                     query="select activityId,title,description from activity where studentProfileId = '${studentProfile.studentProfileId}' "
                     >

                        <field name="activity_id" column="activityId"/>
                        <field name="activity_title" column="title"/>
                        <field name="activity_description" column="description"/>

               </entity>

</entity>

注意${studentProfile.studentProfileId}的写法。
在schema.xml中配置:
 <field name="studentprofile_id" type="string" indexed="true" stored="true" />
   <field name="studentprofile_name" type="text_mmseg4j" indexed="true" stored="true" />
   <field name="studentprofile_location" type="text_mmseg4j" indexed="true" stored="true" />
   <field name="studentprofile_description" type="text_mmseg4j" indexed="true" stored="true" />
   <field name="studentprofile_publicUri" type="text_mmseg4j" indexed="true" stored="true" />

   <field name="activity_id" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="activity_title" type="text_mmseg4j" indexed="true" stored="true" multiValued="true"/>
   <field name="activity_description" type="text_mmseg4j" indexed="true" stored="true" multiValued="true"/>

注意子field中需要配置multiValued="true"
这样配置完成后创建的索引显示结果如下:
"docs": [
      {
        "id": "studentProfile6315bbe5-399f-49b3-9382-b5fb0c2e8e2c",
        "studentprofile_location": "beijing",
        "studentprofile_name": "lcq",
        "studentprofile_id": "6315bbe5-399f-49b3-9382-b5fb0c2e8e2c",
        "activity_id": [
          "1",
          "2"
        ],
        "activity_title": [
          "dfsfs",
          "fsfs"
        ],
        "activity_description": [
          "lcq",
          "haha"
        ],
        "_version_": 1527223001237422000
      }
    ]

配置查询时加权:
在solrconfig.xml中添加
<requestHandler name="search" class="solr.SearchHandler" default="true">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <str name="defType">dismax</str>
       <str name="qf">
          studentprofile_name^1 studentprofile_description^0.8
       </str>
       <str name="q.alt">*:*</str>
       <str name="rows">10</str>
       <str name="fl">*,score</str>
     </lst>
  </requestHandler>
使用solrj查询时:
query.set("qt","search");
即可。




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值