solr 之 datasource

DataSource(数据源)

org.apache.solr.handler.dataimport.DataSource 能被继承。

public abstract class DataSource {
  /**

   * Initializes the DataSource with the Context
 and

   * initialization properties.

   *

* This is invoked by the DataImporter after creating an * instance of this class. * * @param context * @param initProps */ public abstract void init(Context context, Properties initProps); /** * Get records for the given query.The return type depends on the * implementation . * * @param query The query string. It can be a SQL for JdbcDataSource or a URL * for HttpDataSource or a file location for FileDataSource or a custom * format for your own custom DataSource. * @return Depends on the implementation. For instance JdbcDataSource returns * an Iterator> */ public abstract T getData(String query); /** * Cleans up resources of this DataSource after use. */ public abstract void close(); }

它必须在数据源的定义部分被配置。

<dataSource type="com.foo.FooDataSource" prop1="hello"/>


JdbcdataSource

这个是默认的,它的声明如下:

public class JdbcDataSource extends DataSource >>

 

它可以一条一条的遍历数据库,每一行数据被当作一个Map。

HttpDataSource

XPathEntityProcessor使用这个数据源 . 它的声明如下:

public class HttpDataSource extends DataSource

FileDataSource

这个很像HttpDataSource . 它的声明如下:

public class FileDataSource extends DataSource  

The attributes are:

  • basePath: (可选的) ,得到所需要的值时必须的基本路径。

  • encoding: (可选的)当文件编码跟平台编码不一样的时候,应当设定这个值。

posted @ 2014-12-08 09:10  清晰-模块-组合-优化  阅读(637)  评论(0编辑  收藏  举报