1、文件配置

    在core下面新建lib文件夹,存放相关的jar包,如图所示:

    

    

    修改solrconfig.xml

   

<lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
<lib dir="./lib" regex=".*\.jar"/>

    增加配置,如果有则不用添加:

    

 <requestHandler name="/update/extract"
startup="lazy"
class="solr.extraction.ExtractingRequestHandler" >
<lst name="defaults">
<str name="fmap.content">text</str>
<str name="fmap.meta">ignored_</str>
<str name="lowernames">true</str>
<str name="uprefix">attr_</str>
<str name="captureAttr">true</str>
</lst>
</requestHandler>

  配置managed-schema文件:

   

  

  修改managed-schema文件,增加字段:

  <field name="path"      type="string"   indexed="true"  stored="true"  multiValued="false" />
<field name="pathftype" type="string" indexed="true" stored="true" multiValued="false" />
<field name="pathuploaddate" type="string" indexed="true" stored="true" multiValued="false" />
<field name="pathsummary" type="string" indexed="true" stored="true" multiValued="false" />
<field name="attr_content" type="text_general" indexed="true" stored="true" multiValued="false" />

  2、Java代码solrj操作(6.6.0版本) 

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse; /**
* @Author:sks
* @Description:索引pdf等富文本文件
* @Date:Created in 15:16 2017/12/13
* @Modified by:
**/
public class solr_pdf {
public static void main(String[] args)
{ String fileName = "D:/work/Solr/ImportData/20160229001cn.pdf";
String solrId = "20160229001cn.pdf"; try
{
indexFilesSolrCell(solrId, solrId,fileName);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (SolrServerException e)
{
e.printStackTrace();
} } /**
* @Author:sks
* @Description:获取系统当天日期yyyy-mm-dd
* @Date:
*/
private static String GetCurrentDate(){
Date dt = new Date();
//最后的aa表示“上午”或“下午” HH表示24小时制 如果换成hh表示12小时制
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String day =sdf.format(dt);
return day;
} public static void indexFilesSolrCell(String fileName, String solrId, String path)
throws IOException, SolrServerException
{
String urlString = "http://localhost:8983/solr/test";
SolrClient solr = new HttpSolrClient.Builder(urlString).build(); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
String contentType = getFileContentType(fileName);
up.addFile(new File(path), contentType);
String fileType = fileName.substring(fileName.lastIndexOf(".")+1);
up.setParam("literal.id", fileName); up.setParam("literal.path", path);//文件路径
up.setParam("literal.pathuploaddate", GetCurrentDate());//文件上传时间
up.setParam("literal.pathftype", fileType);//文件类型,doc,pdf
up.setParam("fmap.content", "attr_content");//文件内容
up.setAction(ACTION.COMMIT, true, true);
solr.request(up);
} /**
* @Author:sks
* @Description:根据文件名获取文件的ContentType类型
* @Date:
*/
public static String getFileContentType(String filename) {
String contentType = "";
String prefix = filename.substring(filename.lastIndexOf(".") + 1);
if (prefix.equals("xlsx")) {
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
} else if (prefix.equals("pdf")) {
contentType = "application/pdf";
} else if (prefix.equals("doc")) {
contentType = "application/msword";
} else if (prefix.equals("txt")) {
contentType = "text/plain";
} else if (prefix.equals("xls")) {
contentType = "application/vnd.ms-excel";
} else if (prefix.equals("docx")) {
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
} else if (prefix.equals("ppt")) {
contentType = "application/vnd.ms-powerpoint";
} else if (prefix.equals("pptx")) {
contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
} else {
contentType = "othertype";
} return contentType;
}
}

solr6.6 solrJ索引富文本(word/pdf)文件的更多相关文章

  1. 搜索引擎Solr6.2.1 索引富文本(word/pdf/txt/html)

    一:首先建立Core 在core下面新建lib文件夹,存放相关的jar包,如图所示: lib文件夹打开所示,这些类库在solr6.2.1解压之后都能找到: 修改solrconfig.xml,把刚刚建的 ...

  2. 利用 Pandoc 将 Markdown 生成 Word/PDF 文件

    Pandoc 是一个格式转化工具,可以用于各(luan)种(qi)各(ba)样(zao)的文件转换, 反正我是认不全官网上的那个图(傲娇脸), 之前一直使用它将 Markdown 文件转换成 Html ...

  3. SolrCloud索引富文本数据

    solrconfig配置文件: schema配置文件: 执行目录: /opt/solr-5.5.4/server/scripts/cloud-scripts -- 下载配置文件 ./zkcli.sh ...

  4. 个人永久性免费-Excel催化剂功能第88波-批量提取pdf文件信息(图片、表格、文本等)

    日常办公场合中,除了常规的Excel.Word.PPT等文档外,还有一个不可忽略的文件格式是pdf格式,而对于想从pdf文件中获取信息时,常规方法将变得非常痛苦和麻烦.此篇给大家送一pdf文件提取信息 ...

  5. 富文本编辑器UEditor的配置使用方法

    将下载的富文本编辑器的文件解压后放到 webcontent 下 如果 文件中的jsp文件夹下的controller.java文件报错的话    就将jsp下的lib文件夹中的文件都复制到  web-i ...

  6. iOS - 开发中加载本地word/pdf文档说明

    最近项目中要加载一个本地的word/pdf等文件比如<用户隐私政策><用户注册说明>,有两种方法加载 > 用QLPreviewController控制器实现 步骤 : & ...

  7. uedit富文本编辑器及图片上传控件

    微力后台 uedit富文本编辑器及文件上传控件的使用,无时间整理,暂略,参考本地代码.能跑起来.

  8. 给Django后台富文本编辑器添加上传文件的功能

    使用富文本编辑器上传的文件是要放到服务器上的,所以这是一个request.既然是一个request,就需要urls.py进行转发请求views.py进行处理.views.py处理完了返回一个文件所在的 ...

  9. 「Python实用秘技04」为pdf文件批量添加文字水印

    本文完整示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/PythonPracticalSkills 这是我的系列文章「Python实用秘技」的第4期 ...

随机推荐

  1. python3 内置函数(转)

    http://www.runoob.com/python/python-built-in-functions.html divmod(7,2) # 返回(3,1)商和余的元组 frozenset() ...

  2. 【FIRST USE】第一次用git把代码上传到github

    第一次使用某个东西总是充满了伤痛,我第一次用sed的时候,毁掉了我的所有源代码,第一次用git的时候一直提示不正确,后来解决了问题,便记录下来. 首先说明我的环境,我用的是虚拟机,上面运行的64位的c ...

  3. linux知识复习1-dup dup2

    #include <sys/stat.h> #include <string.h> #include <fcntl.h> #include <stdio.h& ...

  4. pressmuSpiderr

    #!/usr/bin/env python # encoding: utf-8 import requests from random import choice from lxml import h ...

  5. 给tomcat单独配置jdk

    在catalina 文件 加这句话,前面加 export JAVA_HOME=/home/apache-tomcat-8.5.8/jdk1.8.0_101

  6. python日志模块笔记

    前言 在应用中记录日志是程序开发的重要一环,也是调试的重要工具.但却很容易让人忽略.之前用flask写的一个服务就因为没有处理好日志的问题导致线上的错误难以察觉,修复错误的定位也很困难.最近恰好有时间 ...

  7. Navigator与UserAgent笔记

    关于Navigator与UserAgent笔记 1.Navigator笔记 Navigator对象主要是包含有关客户端浏览器的一些信息,Navigator对象是由JavaScript runtime ...

  8. MATLAB二维插值和三维插值

    插值问题描述:已知一个函数上的若干点,但函数具体表达式未知,现在要利用已知的若干点求在其他点处的函数值,这个过程就是插值的过程. 1.一维插值 一维插值就是给出y=f(x)上的点(x1,y1),(x2 ...

  9. 使用httpclient异步调用WebAPI接口

    最近的工作需要使用Bot Framework调用原有的WebAPI查询数据,查找了一些方法,大部分都是使用HttpClient调用的,现时贴出代码供参考 using System; using Sys ...

  10. CF984 C. Finite or not?【数论/GCD】

    [链接]:CF [题意]:n组样例,对于每组样例,给你三个数p q b,问你p/q在b进制下是不是一个有限小数,是的话输出Finite,否则输出Infinite. [分析]:b的过程是对q约分,那么只 ...