解决Word文档的检索问题,lucene我的天职是搜索

2009-05-13 02:42:27来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

lunece是个姓氏,Lucene is Doug’s wife’s middle name; it’s also her maternal grandmother’s first name.
看了车东老大的blog,针对MSWord文档的解析器,因为Word文档和基于ASCII的RTF文档不同,
需要使用COM对象机制解析。其实apache的POI完全可以做到解析MSWord文档。
我修改了别人的一个例子,算是抛砖引玉,大家不要那转头打我。
Lucene并没有规定数据源的格式,而只提供了一个通用的结构(Document对象)来接受索引的输入,
但好像只能是文本数据。
package org.tatan.framework;
import java.io.PrintStream;
import java.io.PrintWriter;
public class DocumentHandlerException extends Exception {
  private Throwable cause;
  /**
   * Default constructor.
   */
  public DocumentHandlerException() {
    super();
  }
  /**
   * Constructs with message.
   */
  public DocumentHandlerException(String message) {
    super(message);
  }
  /**
   * Constructs with chained exception.
   */
  public DocumentHandlerException(Throwable cause) {
    super(cause.toString());
    this.cause = cause;
  }
  /**
   * Constructs with message and exception.
   */
  public DocumentHandlerException(String message, Throwable cause) {
    super(message, cause);
  }
  /**
   * Retrieves nested exception.
   */
  public Throwable getException() {
    return cause;
  }
  public void printStackTrace() {
    printStackTrace(System.err);
  }
  public void printStackTrace(PrintStream ps) {
    synchronized (ps) {
      super.printStackTrace(ps);
      if (cause != null) {
        ps.println("--- Nested Exception ---");
        cause.printStackTrace(ps);
      }
    }
  }
  public void printStackTrace(PrintWriter pw) {
    synchronized (pw) {
      super.printStackTrace(pw);
      if (cause != null) {
        pw.println("--- Nested Exception ---");
        cause.printStackTrace(pw);
      }
    }
  }
}
解析MSWORD的类
package org.tatan.framework;
import org.apache.poi.hdf.extractor.WordDocument;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.PrintWriter;
public class POIWordDocHandler  {

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:OSWorkflow 探索

下一篇:spring的interceptors进行参数判断