(二) solr 索引資料匯入:xml格式

來源:互聯網
上載者:User

xml 是最常用的資料索引格式,不僅可以索引資料,還可以對文檔與欄位進行增強,從而改變它們的重要程度。

下面就是具體的實現方式:

schema.xml的欄位配置部分如下:

<field name="id" type="string" stored="true" indexed="true"/><field name="name" type="string" stored="true" indexed="true" omitNorms="false"/><field name="isbn" type="string" stored="true" indexed="true"/>

以下是我們將要提交到solr作為索引的xml文檔:books.xml

<add overwrite="true" commitWithin="10000"><doc><field name="id">1</field><field name="isbn">ABC1234</field><field name="name" boost="2">Some Book</field></doc><doc boost="2.5"><field name="id">2</field><field name="isbn">ZYVW9821</field><field name="name" boost="2">Important Book</field></doc><doc><field name="id">3</field><field name="isbn">NXJS1234</field><field name="name" boost="2">Some other book</field></doc></add>

 

說明:

overwrite="true" :告訴solr在做索引的時候,如果文檔已經存在,就用xml中的文檔進行替換

commitWithin="10000" :告訴solr 在做索引的時候,每個10000(10s)毫秒,做一次文檔提交

boost:用來指明文檔或者欄位的重要程度,預設值為:1.0,在這個樣本中,第二個文檔的boost值為2.5,表示比其它兩個文檔更重要

omitNorms="false":這個屬性值表示是否忽略欄位的的規範,此處設為否。如果要在做索引的時候指定欄位的重要程度,必須使用欄位的長度規範。

                              如果設定為true,那麼這些欄位在索引時不會增加重要程度

 

如果在linux下,我們可以使用下面的方式提交文檔

curl http://localhost:8983/solr/update --data-binary @books.xml -H 'Content-type:text/xml; charset=utf-8'

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.