solr总结(一)

                                                      solr总结(一)

The default port configured for Solr during the install process is 8983
You will need the Java Runtime Environment (JRE) version 1.6 or higher.
To confirm your installation, go to the Solr Admin page at http://localhost:8983/solr/. 
=================================================
To install Solr
1 Unpack the Solr distribution to your desired location.
2 Stop your Java servlet container.
3 Copy the solr.war file from the Solr distribution to the webapps directory of your servlet container. Do not change the name of this file:
it must be named solr.war.
4 Copy the Solr Home directory solr-4.x.0/example/solr/ from the distribution to your desired Solr Home location.
5 Start your servlet container, passing to it the location of your Solr Home in one of these ways:
    (1)Set the Java system property solr.solr.home to your Solr Home. (for example, using the example jetty setup: java
-Dsolr.solr.home=/some/dir -jar start.jar).
   (2)Configure the servlet container so that a JNDI lookup of java:comp/env/solr/home by the Solr webapp will point to your Solr
Home.
   (3)Start the servlet container in the directory containing ./solr: the default Solr Home is solr under the JVM's current working
directory ($CWD/solr).
=================================================
If you didn't start Solr after installing it, you can start it by running start.jar from the Solr example directory.
$ java -jar start.jar
If you are running Windows, you can start the Web server by running start.bat instead.
C:\Applications\Solr\example > start.bat
================================================
solr.xml 
     specifies configuration options for your Solr core, and also allows you to configure multiple cores. 
solrconfig.xml 
     controls high-level behavior. You can, for example, specify an alternate location for the data directory. 
schema.xml 
     describes the documents you will ask Solr to index. Inside schema.xml, you define a document as a collection of fields. You get to
define both the field types and the fields themselves. Field type definitions are powerful and include information about how Solr processes
incoming field values and query values. 
=============================================
Configuring the Admin UI in solrconfig.xml
<admin>
<defaultQuery>solr</defaultQuery>
</admin>
========================================26
SolrJ is an API that makes it easy for Java applications to talk to Solr. SolrJ hides a lot of the details of connecting to Solr and allows your
application to interact with Solr with simple high-level methods.
The center of SolrJ is the org.apache.solr.client.solrj package, which contains just five main classes. Begin by creating a SolrServer
, which represents the Solr instance you want to use. Then send SolrRequests or SolrQuerys and get back SolrResponses.
SolrServer is abstract, so to connect to a remote Solr instance, you'll actually create an instance of HttpSolrServer, which knows how to
use HTTP to talk to Solr.
String urlString = "http://localhost:8983/solr";
SolrServer solr = new HttpSolrServer(urlString);
======================================
SolrQuery parameters = new SolrQuery();
parameters.set("q", mQueryString);
parameters.set("qt", "/spellCheckCompRH");
QueryResponse response = solr.query(parameters);
SolrDocumentList list = response.getResults();
=====================================
String urlString = "http://localhost:8983/solr";
SolrServer solr = new HttpSolrServer(urlString);
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "552199");
document.addField("name", "Gouda cheese wheel");
document.addField("price", "49.99");
UpdateResponse response = solr.add(document);
// Remember to commit your changes!
solr.commit();
==================================================
<!--数据库字符串的配置-->
    <document><!--
    transformer 格式转换:HTMLStripTransformer 索引中忽略HTML标签
    query:完全索引查询语句
    deltaQuery:增量索引查询主键ID
    deltaImportQuery:增量索引查询导入数据
    deletedPkQuery:增量索引删除主键ID查询
-->
<dataConfig>
<dataSource driver="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://localhost:1433/webmsg" user="sa" password="sa"/>
    <document name="doc">
        <entity name="msg" pk="ID" transformer="HTMLStripTransformer" query="select * from msg" deltaQuery="select * from msg where msglastmodifytime > '${dataimporter.last_index_time}'">
            <field column="ID"/>
            <field column="MSGTITLE"/>
            <field column="MSGCONTENT" stripHTML="true"/><!--查询字段名,配置字段名,是否使用格式化-->
            <field column="MSGURL"/>
            <field column="MSGDATE"/>
        </entity>
    </document>
</dataConfig>
------------------------------------------------------------
·dataSource:数据源,也可配置在solrConfig.xml中
·type:指定了实现的类型,是可选的,默认是"JdbcDataSource"
·name:是dataSource的名字,当有多个datasource时,可使用name属性加以区分
·document:包含一个或多个entity
·entity:可理解为javabean或数据库中的表
·field:可理解为属性名或列名
·query:如何获取数据
·column:表的列名
·name:schema.xml中所配置的字段名
----------------------------------------------------------
data-config.xml
根元素是document。一个document代表了一种文档。一个document元素包含一个或者多个root实体。一个root实体包含多个子实体。
实体实际就是数据库中的表或者视图。
entity属性:
name 唯一标识,用于识别entity
processor:只有当datasource是RDBMS时才是必须的。默认是SqlEntityProcessor
transformer:转换器将会被应用到这个entity上。
pk:entity的主键,可选。但是用增量导入的时候是必需的。它跟schema.xml中定义的uniqueKey没有必然的联系。但他们可以相同。
rootEntity:document元素下就是根实体,每一个实体就是一个document
SqlEntityProcessor的一些属性
query 必须的 sql语句
deltaQuery 增量导入的时候使用
parentDeltaQuery 增量导入的时候使用
deletedPKQuery 增量导入的时候使用
deltaImportQuery 增量导入的时候使用,如果这个存在,那么他将会在增量导入中导入phase时替代query产生作用。 
-------------------------------------------------------
第一部分是对《db-data-config.xml》


query是获取全部数据的SQL
deltaImportQuery是获取增量数据时使用的SQL
deltaQuery是获取pk的SQL
parentDeltaQuery是获取父Entity的pk的SQL


Full Import工作原理:
执行本Entity的Query,获取所有数据;
针对每个行数据Row,获取pk,组装子Entity的Query;
执行子Entity的Query,获取子Entity的数据。


Delta Import工作原理:
查找子Entity,直到没有为止;
执行Entity的deltaQuery,获取变化数据的pk;
合并子Entity parentDeltaQuery得到的pk;
针对每一个pk Row,组装父Entity的parentDeltaQuery;
执行parentDeltaQuery,获取父Entity的pk;
执行deltaImportQuery,获取自身的数据;
如果没有deltaImportQuery,就组装Query


限制:
子Entity的query必须引用父Entity的pk
子Entity的parentDeltaQuery必须引用自己的pk
子Entity的parentDeltaQuery必须返回父Entity的pk
deltaImportQuery引用的必须是自己的pk
--------------------------------------------------------------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值