`
baeiou
  • 浏览: 4234 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

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

    博客分类:
  • solr
阅读更多

当用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了!

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics