简单介绍

java web开发的同学应该非常熟悉,在开发中常常会使用filter来处理请求中的一些切面需求。

solr也提供类似的一种链式结构的handler来满足在加入数据索引请求的时候。通过切片的形式,添加一个handler来对请求进行加工。

配置在SORL_HOME\collection1\conf\solrconfig.xml文件里。配置方式例如以下:

 <updateRequestProcessorChain name="mychain" default="true">
<processor class="solr.CustomUpdateRequestProcessorFactory" >
<lst name="name">
<str name="n1">x1</str>
<str name="n2">x2</str>
</lst>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

假设配置文件里没有指定一个"default"。solr会默认选择LogUpdateProcessorFactory 和 RunUpdateProcessorFactory作为默认的handler。

怎样选择所配置的UpdateChain

1.通过在url中传參数,比如http://localhost:8983/solr/update/xml?update.chain=mychain

2.在SolrRequestHandler配置中,指定相应的UpdateChain,在SORL_HOME\collection1\conf\solrconfig.xml文件里。配置例如以下:

 <!-- referencing it in an update handler -->
<requestHandler name="/update/processortest" class="solr.JsonUpdateRequestHandler" >
<lst name="defaults">
<str name="update.chain">mychain</str>
</lst>
</requestHandler>

通过这个配置,当你发起一个/update/processortest请求的时候,就会选择JsonUpdateRequestHandler,然后该Handler会默认选择一个名为mychain的UpdateChain,假设不知道JsonUpdateRequestHandler是什么东西,能够參考之前的章节。http://blog.csdn.net/jaynol/article/details/24959373

一个简单的UpdateChain样例

样例的需求是,新增“cat”字段,仅仅有当“popularity”的值大于5的时候才干新增。

代码例如以下:

package my.solr;

import java.io.IOException;

import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory; public class ConditionalCopyProcessorFactory extends UpdateRequestProcessorFactory
{
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)
{
return new ConditionalCopyProcessor(next);
}
} class ConditionalCopyProcessor extends UpdateRequestProcessor
{
public ConditionalCopyProcessor( UpdateRequestProcessor next) {
super( next );
} @Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
SolrInputDocument doc = cmd.getSolrInputDocument(); Object v = doc.getFieldValue( "popularity" );
if( v != null ) {
int pop = Integer.parseInt( v.toString() );
if( pop > 5 ) {
doc.addField( "cat", "popular" );
}
} // pass it up the chain
super.processAdd(cmd);
}
}

配置例如以下:

 <updateRequestProcessorChain name="mychain" default="true">
<processor class="my.solr.ConditionalCopyProcessorFactory" />
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

8.跟我学solr---UpdateRequestProcessor具体解释的更多相关文章

  1. solr与.net系列课程(一)solr的安装与配置

    不久之前开发了一个项目,需要用到solr,因为所以在开始再网上查找资料,但是发现大部分的资料都是很片面的,要么就是只讲解solr如何安装的,要么就是只讲解solr的某一个部分的,而且很多都是资料都是一 ...

  2. 企业级搜索引擎Solr 第三章 索引数据(Indexing Data)[3]

    转载:http://quweiprotoss.wap.blog.163.com/ Solr Cell是一个针对Tika的简单适配器,它由一个SAX ContentHandler组成,ContentHa ...

  3. solr的安装与配置

    solr的安装与配置 不久之前开发了一个项目,需要用到solr,因为所以在开始再网上查找资料,但是发现大部分的资料都是很片面的,要么就是只讲解solr如何安装的,要么就是只讲解solr的某一个部分的, ...

  4. 企业级搜索引擎Solr 第三章 索引数据(Indexing Data)

    虽然本书中假设你要建索引的内容都是有着良好结构的,比如数据库表,XML文件,CSV,但在现实中我们要保存很混乱的数据,或是二进制文件,如PDF,Microsoft Office,甚至是图片和音乐文件. ...

  5. solr简易安装配置

    之前弄了段时间的lucene,昨天下午开始学solr,准备用到项目中,在网上找了一些教程,有的不是讲得太复杂,就是讲得不在点上,花了不少冤枉时间.有的一上来就花过半的篇幅大讲特讲“3H”,(what, ...

  6. Solr笔记--转载

    Solr 是一种可供企业使用的.基于 Lucene 的搜索服务器,它支持层面搜索.命中醒目显示和多种输出格式.在这篇分两部分的文章中,Lucene Java™ 的提交人 Grant Ingersoll ...

  7. 跟我学solr---吐槽一下,我的文章被抄袭啦

    今天闲来无事,就在在百度上搜了下面"跟我学solr",看看这几周来自己的努力成果怎么样,不搜还好,搜了就图学了.被原封不动地抄袭了!并且抄袭的文章还在百度排名第一,我自己的却被排到 ...

  8. Solr Date类型的哪些你不得不了解的细节

    我们先来看看Solr日期类型的一些内幕,然后讨论一下Solr日期类型存在的一些问题,最后我们看看怎么解决现存的问题.概述 DateField 在Solr4.x之前,我们只有DateField,这类型现 ...

  9. Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler--转载

    原文地址:https://gist.github.com/maxivak/3e3ee1fca32f3949f052 Install Solr download and install Solr fro ...

  10. Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml)(1)

    刚学Solr(版本6.7.0),新建一个core时,提示要求schema.xml文件,我找了半天也没在源码包中找到名为schema.xml的文件.这个版本其实用的是managed-schema文件,没 ...

随机推荐

  1. 【计算机网络】2.2 Web和HTTP

    第二章第二节 Web和HTTP 这一章中,我们需要讨论5种重要的应用:Web.文件传输.电子邮件.目录服务.P2P:这一节中,我们将讨论Web和它的应用层协议HTTP. Outline Web简介 H ...

  2. vim 删除单个单词,cc和dd关系

    c         功能和d相同,区别在于完成删除操作后进入INSERT MODE cc       也是删除当前行,然后进入INSERT MODE 删除每行第一个字符    :%s/^.//g   ...

  3. What is state and props

    State, in React component, is internal dataset which affects the rendering of the component. To some ...

  4. vue 画二维码

    首先安装一下相关的插件 qrcode2 npm install --save qrcode2 然后在需要画二维码的页面引入一下 import QRCode from 'qrcode2' 最后在meth ...

  5. LeetCode 303. Range Sum Query – Immutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  6. QueryParser

    [概述] 其他工具类使用比较方便,但不够灵活.QueryParser也实现了较多的匹配方式. [QueryParser的应用] /** * 使用QueryParser进行查询 * @throws Pa ...

  7. HDU 2475 Box

    Box Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 247564 ...

  8. K-th Number POJ - 2104 划分树

    K-th Number You are working for Macrohard company in data structures department. After failing your ...

  9. Ubuntu12.04之修改密码

    Ubuntu 12.04 默认root没有密码 修改密码方式如下: test@localhost:~$ sudo passwd root [sudo] password for test: 输入新的 ...

  10. HDU 5641 King's Phone【模拟】

    题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...