SolrServer实现类

HttpSolrServer

HttpSolrServer uses the Apache Commons HTTPClient to connect to solr.

HttpSolrServer is thread-safe and if you are using the following constructor, you must re-use the same instance for all request.

if instances are created on the fly, it can cause a connection leak. The recommended practice is to keep a static instance of HttpSolrServer per solr server url and share it for all requests.

LBHttpSolrServer

LBHttpSolrServer or "LoadBalanced HttpSolrServer" is a load balancing wrapper around org.apache.solr.client.solrj.impl.HttpSolrServer. This is useful when you have multiple SolrServers and the requests need to be Load Balanced among them. Do NOT use this class for indexing in master/slave scenarios since documents must be sent to the correct master; no inter-node routing is done. In SolrCloud (leader/replica) scenarios, this class may be used for updates since updates will be forwarded to the appropriate leader. Also see the wiki page.

It offers automatic failover when a server goes down and it detects when the server comes back up.【容灾】

Load balancing is done using a simple round-robin on the list of servers.【负载均衡】

If a request to a server fails by an IOException due to a connection timeout or read timeout then the host is taken off the list of live servers and moved to a 'dead server list' and the request is resent to the next live server. This process is continued till it tries all the live servers. If at least one server is alive, the request succeeds, and if not it fails.

 SolrServer lbHttpSolrServer = new LBHttpSolrServer("http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr");
//or if you wish to pass the HttpClient do as follows
httpClient httpClient = new HttpClient();
SolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient,"http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr");

This detects if a dead server comes alive automatically. The check is done in fixed intervals in a dedicated thread. This interval can be set using setAliveCheckInterval , the default is set to one minute.【容灾,自感知节点复活】

When to use this?
This can be used as a software load balancer when
you do not wish to setup an external load balancer. Alternatives to this code
are to use a dedicated hardware load balancer or using Apache httpd with
mod_proxy_balancer as a load balancer. See Load balancing on
Wikipedia

CloudSolrServer

SolrJ client class to communicate with SolrCloud. Instances of this class communicate with Zookeeper to discover Solr endpoints for SolrCloud collections, and then use the LBHttpSolrServer to issue requests. This class assumes the id field for your documents is called 'id' - if this is not the case, you must set the right name with setIdField(String).

-- SolrJ includes a 'smart' client for SolrCloud, which is ZooKeeper aware. This means that your Java application only needs to know about your Zookeeper instances, and not where your Solr instances are, as this can be derived from Zookeeper.

ConcurrentUpdateSolrServer

ConcurrentUpdateSolrServer buffers all added documents and writes them into open HTTP connections. This class is thread safe. Params from UpdateRequest are converted to http request parameters. When params change between UpdateRequests a new HTTP request is started. Although any SolrServer request can be made with this implementation, it is only recommended to use ConcurrentUpdateSolrServer with /update requests. The class HttpSolrServer is better suited for the query interface.

SolrServer主要方法

主要方法add、delete、query、commit、optimize等。

这些方法都是根据请求构建对应的SolrRequest,然后执行SolrRequest的process方法。

public abstract SolrResponse process( SolrServer server ) throws SolrServerException, IOException;

SolrRequest的类结构

例如,QueryRequest的process重载:

@Override
public QueryResponse process( SolrServer server ) throws SolrServerException
{
try {
long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
QueryResponse res = new QueryResponse( server.request( this ), server );
long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
res.setElapsedTime(endTime - startTime);
return res;
} catch (SolrServerException e){
throw e;
} catch (SolrException s){
throw s;
} catch (Exception e) {
throw new SolrServerException("Error executing query", e);
}
}

-----------------------------

http://wiki.apache.org/solr/Solrj

http://wiki.apache.org/solr/LBHttpSolrServer

SolrServer SolrRequest的更多相关文章

  1. Solr入门之SolrServer实例化方式

    随着solr版本的不断升级, 差异越来越大, 从以前的 solr1.2 到现在的 solr4.3, 无论是类还是功能都有很大的变换, 为了能及时跟上新版本的步伐, 在此将新版本的使用做一个简单的入门说 ...

  2. solrserver实例化

    以下是httpClient实例化方式,需要tomcat运行Solr服务 1.ConcurrentUpdateSolrServer实例化SolrServer,该类实例化多用于更新删除索引操作 Concu ...

  3. Solr 02 - 最详细的solrconfig.xml配置文件解读

    目录 1 luceneMatchVersion - 指定Lucene版本 2 lib - 配置扩展jar包 3 dataDir - 索引数据路径 4 directoryFactory - 索引存储工厂 ...

  4. solr中facet及facet.pivot理解(整合两篇文章保留参考)

    Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...

  5. solr中facet及facet.pivot理解

    Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...

  6. 8.solr学习速成之FacetPivot

    什么是Facet.pivot  Facet.pivot就是按照多个维度进行分组查询,是Facet的加强,在实际运用中经常用到,一个典型的例子就是商品目录树 NamedList解释: NamedList ...

  7. solr开发之基本操作

    package zr.com.util; import java.io.IOException; import java.util.List; import java.util.Map; import ...

  8. (三)Solrj4到Solrj5的升级之路

    (三)Solrj4到Solrj5的升级之路 Solr5发布了,带来了许多激动人心的新特性,但Solrj的许多接口也发生了变化,升级是痛苦的,但也是必须的,下面就赶紧来看看有哪些代码需要升级吧. 变化1 ...

  9. Solr分组查询

     项目中需要实时的返回一下统计的东西,因此就要进行分组,在获取一些东西,代码拿不出来,因此分享一篇,还是很使用的. facet搜索 /** * * 搜索功能优化-关键词搜索 * 搜索范围:商品名称.店 ...

随机推荐

  1. CF1120 C. Compress String(SAM+DP)

    有方程dp[i]=min(dp[i-1]+A,dp[j]+B):如果s[j+1,i]在s[i,j]中出现,所以我们就是要知道每个子串在s出现的第一个位置,这个可以hash实现或者sam,或者kmp实现 ...

  2. Plant(𝐶𝑜𝑑𝑒𝐹𝑜𝑟𝑐𝑒𝑠 − 185𝐴)

    #include<iostream> #include<cstring> using namespace std; ,mod=; struct Matrix { long lo ...

  3. strchr与sscanf

    strchr(s,',')返回字符串s中从左往右第一个字符's'的指针: sscanf(输入的字符或字符串,“%格式符”,存储值):

  4. wireshark显示过滤器的几种用法(转自他人博客)

    本文章转自:http://blog.51cto.com/houm01/1872652 几种条件操作符 ==   eq    等于    ip.addr == 192.168.0.1   ip.addr ...

  5. Linux下7z工具安装

    sudo apt-get install p7zip p7zip-full p7zip-rar 使用: 使用7z --help查看使用方法. 解压: 7za X test.7z

  6. 【JVM】java对象

    一.对象内存布局 对象在内存中存储可分为3块区域:对象头,实例数据,对齐填充 1.对象头 对象头包含两部分内容. 第一部分:存储对象自身的运行时数据,哈希吗(hashCode),GC分代年龄,锁状态标 ...

  7. kubebapps 添加私有harbor 中的helm repo

    kubebapps 支持添加私有的helm repo,基于http basic auth ,我们通过添加header 就可以了 备注 harbor helm 以及kubebapps 的搭建可以参考 h ...

  8. 05C++引用

    1.变量名 变量名实质上是一段连续存储空间的别名,是一个标号(门牌号): 通过变量来申请并命名内存空间: 通过变量的名字可以使用内存空间. 2.引用的概念 变量名,本身是一段内存的引用,即别名(ali ...

  9. 来自工厂的 PCB 封装建议

    来自工厂的 PCB 封装建议 以前一直没有注意,现在终于知道了,PCB 的封装方向角度是不可以乱摆的,要根据实际编带情况画. 以实物的编带为参考确定 PCB 封装的画法. 而且编带都有标准. 强烈建议 ...

  10. storage 事件监听

    在公司的一次内部分享会上, 偶然知道了这个H5的新事件, 解决了我之前的一个bug. 事情是这样的, 第A网页上显示的数量的总和, 点击去是B页面, 可以进行管理, 增加或者删除, 当用户做了增删操作 ...