solr實體嵌套、欄位加權查詢__solr

來源:互聯網
上載者:User
建立索引時可能遇到實體嵌套的情況,比如學生資訊中包含多個活動。

在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");
即可。




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.