solr中为pdf word excel等文档做索引和存诸时如何把回车空格等去掉

当用solr"/update/extract"方法为pdf 或 word 或excel 等文件做索引时,当高亮时总会出现很多回车或空格占了很多空间,让搜索结果时长时短很不好看,而配设中又没有配置可以完成这项目功能,唯一可以实现的就是改源码!

我用的是solr4.7.2的源码去改,源码在以下网址找到

http://grepcode.com/snapshot/repo1.maven.org/maven2/org.apache.solr/solr-cell/4.7.2/

改的文件是

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.solr/solr-cell/4.7.2/org/apache/solr/handler/extraction/SolrContentHandler.java

改的地方是:

改动如下:

添加 private char LastChar=7;

public void startElement 去掉 bldrStack.getLast().append(' ');

public void endElement 去掉 bldrStack.getLast().append(' ');

public void characters(char[] chars, int offset, int length) throws SAXException

改为如下:

  public void characters(char[] chars, int offset, int length) throws SAXException {

if(chars.length>0)

{

char[] TmpChars=new char[chars.length];

int TmpCharsCount=0;

for(int i=offset;i<chars.length;i++)

{

if(chars[i]=='\n' || chars[i]=='\r' || chars[i]=='\t' || chars[i]==' ' || chars[i]==' ')

{

if(LastChar!=' ')

{

TmpChars[TmpCharsCount]=' ';

TmpCharsCount++;

LastChar=' ';

}

else

{

TmpChars[TmpCharsCount]=chars[i];

TmpCharsCount++;

LastChar=chars[i];

}

}

if(TmpCharsCount>0)

{

bldrStack.getLast().append(TmpChars, 0, TmpCharsCount);

}

}

  }

然后解压solr-cell-4.7.2.jar这个文件,替换里面的SolrContentHandler.class文件,再重新打包成zip文件再把后辍改成jar,这样替换掉原来的solr-cell-4.7.2.jar就OK了!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值