fjqzyc 发表于 2015-7-17 10:48:36

Solr data import 中XML/HTTP 数据源的使用

Solrdataimport 中XML/HTTP 数据源的使用

  参考自:http://wiki.apache.org/solr/DataImportHandler
  DataImportHandler 可以通过datasource数据源索引来自于HTTP的数据。包括REST/XML和RSS/ATOM 。
  在版本1.4中,推荐使用URLDataSource。
  配置示例如下:
  



Xml代码 http://forchenyun.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf?clipboard=%3CdataSource%20name%3D%22b%22%20type%3D%22HttpDataSource%22%20baseUrl%3D%22http%3A%2F%2Fhost%3Aport%2F%22%20encoding%3D%22UTF-8%22%20connectionTimeout%3D%225000%22%20readTimeout%3D%2210000%22%2F%3E%0A%3C!--%20or%20in%20Solr%201.4--%3E%0A%3CdataSource%20name%3D%22a%22%20type%3D%22URLDataSource%22%20baseUrl%3D%22http%3A%2F%2Fhost%3Aport%2F%22%20encoding%3D%22UTF-8%22%20connectionTimeout%3D%225000%22%20readTimeout%3D%2210000%22%2F%3E
[*]
[*]
[*]
    datasource的属性有:  baseUrl(可选): you should use it when the host/port changes between Dev/QA/Prod environments. Using this attribute isolates the changes to be made to the solrconfig.xml
  encoding(可选):定义响应头里面的编码方式。这个属性可以替换掉服务器的默认编码方式。
  connectionTimeout(可选):默认时间是5000ms
  readTimeout(可选):默认是10000ms
  
  下面是一个data-config.xml示例的配置:
  这是一个Slashdot RSS feed的例子。
  



Xml代码 http://forchenyun.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf?clipboard=%3CdataConfig%3E%0A%20%20%20%20%20%20%20%20%3CdataSource%20type%3D%22HttpDataSource%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%3Cdocument%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Centity%20name%3D%22slashdot%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pk%3D%22link%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20url%3D%22http%3A%2F%2Frss.slashdot.org%2FSlashdot%2Fslashdot%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20processor%3D%22XPathEntityProcessor%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20forEach%3D%22%2FRDF%2Fchannel%20%7C%20%2FRDF%2Fitem%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20transformer%3D%22DateFormatTransformer%22%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22source%22%20%20%20%20%20%20%20xpath%3D%22%2FRDF%2Fchannel%2Ftitle%22%20%20%20commonField%3D%22true%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22source-link%22%20%20xpath%3D%22%2FRDF%2Fchannel%2Flink%22%20%20%20%20commonField%3D%22true%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22subject%22%20%20%20%20%20%20xpath%3D%22%2FRDF%2Fchannel%2Fsubject%22%20commonField%3D%22true%22%20%2F%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22title%22%20%20%20%20%20%20%20%20xpath%3D%22%2FRDF%2Fitem%2Ftitle%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22link%22%20%20%20%20%20%20%20%20%20xpath%3D%22%2FRDF%2Fitem%2Flink%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22description%22%20%20xpath%3D%22%2FRDF%2Fitem%2Fdescription%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22creator%22%20%20%20%20%20%20xpath%3D%22%2FRDF%2Fitem%2Fcreator%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22item-subject%22%20xpath%3D%22%2FRDF%2Fitem%2Fsubject%22%20%2F%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22slash-department%22%20xpath%3D%22%2FRDF%2Fitem%2Fdepartment%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22slash-section%22%20%20%20%20xpath%3D%22%2FRDF%2Fitem%2Fsection%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22slash-comments%22%20%20%20xpath%3D%22%2FRDF%2Fitem%2Fcomments%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22date%22%20xpath%3D%22%2FRDF%2Fitem%2Fdate%22%20dateTimeFormat%3D%22yyyy-MM-dd
[*]
[*]         
[*]         
[*]                  
[*]
[*]                        
[*]                        
[*]                        
[*]
[*]                        
[*]                        
[*]                        
[*]                        
[*]                        
[*]
[*]                        
[*]                        
[*]                        
[*]                        
[*]                  
[*]         
[*]
                                                                                                                                                                                                                                                                                                                                                                              看到这个东西的确有点迷糊,因此下面是我们索引wikipedia的例子:  下面这个data-config.xml是用于索引http://dumps.wikimedia.org/enwiki/20100312/ 这个网页下的pages-articles.xml.bz2文件,我们需要去这个网页下载该文件,解压以后放到conf/data目录下,这个文件不压缩的大小是1.50GB。
  



Xml代码 http://forchenyun.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf?clipboard=%3CdataConfig%3E%0A%20%20%20%20%20%20%20%20%3CdataSource%20type%3D%22FileDataSource%22%20encoding%3D%22UTF-8%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%3Cdocument%3E%0A%20%20%20%20%20%20%20%20%3Centity%20name%3D%22page%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20processor%3D%22XPathEntityProcessor%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stream%3D%22true%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20forEach%3D%22%2Fmediawiki%2Fpage%2F%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20url%3D%22%2Fdata%2Fenwiki-20100312-pages-articles.xml%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20transformer%3D%22RegexTransformer%2CDateFormatTransformer%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22id%22%20%20%20%20%20%20%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Fid%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22title%22%20%20%20%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Ftitle%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22revision%22%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Frevision%2Fid%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22user%22%20%20%20%20%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Frevision%2Fcontributor%2Fusername%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22userId%22%20%20%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Frevision%2Fcontributor%2Fid%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22text%22%20%20%20%20%20%20xpath%3D%22%2Fmediawiki%2Fpage%2Frevision%2Ftext%22%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cfield%20column%3D%22timestamp%22%20xpath%3D%22%2Fmediawiki%2Fpage%2Frevision%2Ftimestamp%22%20dateTimeFormat%3D%22yyyy-MM-dd
[*]
[*]         
[*]         
[*]         
[*]            
[*]            
[*]            
[*]            
[*]            
[*]            
[*]            
[*]            
[*]         
[*]         
[*]
                                                                                                                                                      注意一下上面的url最好写绝对路径,我的相对路径老是出错-_-。  相关的schema.xml文件如下:
  



Xml代码 http://forchenyun.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf?clipboard=%3Cfield%20name%3D%22id%22%20%20%20%20%20%20%20%20type%3D%22integer%22%20indexed%3D%22true%22%20stored%3D%22true%22%20required%3D%22true%22%2F%3E%0A%3Cfield%20name%3D%22title%22%20%20%20%20%20type%3D%22string%22%20%20indexed%3D%22true%22%20stored%3D%22false%22%2F%3E%0A%3Cfield%20name%3D%22revision%22%20%20type%3D%22sint%22%20%20%20%20indexed%3D%22true%22%20stored%3D%22true%22%2F%3E%0A%3Cfield%20name%3D%22user%22%20%20%20%20%20%20type%3D%22string%22%20%20indexed%3D%22true%22%20stored%3D%22true%22%2F%3E%0A%3Cfield%20name%3D%22userId%22%20%20%20%20type%3D%22integer%22%20indexed%3D%22true%22%20stored%3D%22true%22%2F%3E%0A%3Cfield%20name%3D%22text%22%20%20%20%20%20%20type%3D%22text%22%20%20%20%20indexed%3D%22true%22%20stored%3D%22false%22%2F%3E%0A%3Cfield%20name%3D%22timestamp%22%20type%3D%22date%22%20%20%20%20indexed%3D%22true%22%20stored%3D%22true%22%2F%3E%0A%3Cfield%20name%3D%22titleText%22%20type%3D%22text%22%20%20%20%20indexed%3D%22true%22%20stored%3D%22true%22%2F%3E%0A...%0A%3CuniqueKey%3Eid%3C%2FuniqueKey%3E%0A%3CcopyField%20source%3D%22title%22%20dest%3D%22titleText%22%2F%3E%0A
[*]
[*]
[*]
[*]
[*]
[*]
[*]
[*]
[*]...
[*]id
[*]
      ... id    下面会花费数小时的时间去索引数据,并且内存使用率将持续最高,请注意很多wikipedia的文章都仅仅是指向其它文章$skipDoc(1.4)的使用可以使得这些文章被忽略,当然前提是正则表达式匹配。  请注意:由于目前唯一支持delta import的EntityProcessor是SqlEntityProcessor,而XPathEntityProcessor并现在没有实现delta import。如果你想实现这些方法的话,你需要修改EntityProcessor.java         
页: [1]
查看完整版本: Solr data import 中XML/HTTP 数据源的使用