solrj创建富文本索引
来源:互联网 发布:乌克兰金丝猫事件知乎 编辑:程序博客网 时间:2024/05/01 17:45
今天主要使用solrj为富文本内容创建索引,参考网上的例子,一直没有调试成功。solrj客户端报的是org.apache.solr.common.SolrException: Internal Server Error错误,没有提示任何信息,因此自己感觉一头雾水,不知从何下手。solr程序后台没有报任何错误。
后来把dist文件夹下的lib包都拷贝到solr程序中,solr后台终于显示了错误信息。根据错误信息的提示把contrib\extraction下的所有jar报都拷贝到solr程序中,程序终于运行起来了。
下面是利用solrj创建富文本内容索引的程序。
import java.io.File;import java.io.IOException;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;import org.apache.solr.client.solrj.request.AbstractUpdateRequest;import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;import org.apache.solr.client.solrj.response.QueryResponse;public class SolrJDemo2 { public static void main(String[] args) { try { //Solr cell can also index MS file (2003 version and 2007 version) types. String fileName = "D://lucene3//SQL性能优化.docx"; //this will be unique Id used by Solr to index the file contents. String solrId = "SQL性能优化"; indexFilesSolrCell(fileName, solrId); } catch (Exception ex) { System.out.println(ex.toString()); } } /** * Method to index all types of files into Solr. * @param fileName * @param solrId * @throws IOException * @throws SolrServerException */ public static void indexFilesSolrCell(String fileName, String solrId) throws IOException, SolrServerException { String urlString = "http://127.0.0.1:8080/solr"; SolrServer solr = new CommonsHttpSolrServer(urlString); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract"); up.addFile(new File(fileName)); up.setParam("literal.id", solrId); up.setParam("fmap.content", "attr_content"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); solr.request(up); QueryResponse rsp = solr.query(new SolrQuery("*:*")); System.out.println(rsp); }}
up.setParam("literal.id", solrId); //设置document的id域值为solrid
up.setParam("fmap.content", "msg_content");//设置存储文件内容的域为msg_content,我们必须在schema.xml中定义msg_content字段。
0 0
- solrj创建富文本索引
- 使用SolrJ创建索引
- AttributedString创建富文本
- Solrj创建doc/pdf/txt文件索引,高亮查询
- solrj的使用,环境准备,工程搭建,索引创建,添加\修改索引,删除索引,查询
- SolrJ提交索引
- solrj实现增量索引
- solrj 文件索引问题
- SolrJ 操作索引文档
- SolrJ 管理索引库
- solr_对富文本(pdf等)建立索引
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 富文本
- 最简单的事件广播类
- KVM搭建和其中虚拟机创建
- iOS 7 教程:定制iOS 7中的导航栏和状态栏
- iBatis 到 MyBatis区别
- PHP_XML_DOM
- solrj创建富文本索引
- 图解GIT
- 新年寄语
- vs2010快捷键
- SQL Server2008函数大全(完整版)
- iOS7,iPhone 5S和iPad Air:苹果的2013
- AVR——使用定时器必须弄清的几个概念!
- Android中handler的用法
- mac下完全卸载postgresql的方法