/**
* 文檔主體建立索引
* 注意文檔與附件分成不同的Document,但搜索到附件內容時,需鏈接到其所在文檔
* @param article
* @return
* @throws InterruptedException
* @throws Exception
*/
private Document createArticleIndex(Article article) throws Exception{
Document document = new Document();
//ID
document.add(new Field("id", article.getId(), Field.Store.YES,
Field.Index.UN_TOKENIZED));
//文檔ID
document.add(new Field("articleId", article.getId(), Field.Store.YES,
Field.Index.UN_TOKENIZED));
//文檔標題
document.add(new Field("topic", article.getTopic(), Field.Store.YES,
Field.Index.TOKENIZED));
//文檔分類
document.add(new Field("categoryId", article.getCategoryId(),
Field.Store.YES, Field.Index.TOKENIZED));
String content = article.getContent();
//注意文章內容支持html標簽,故此處需提取文本內容
HTMLParser parser = new HTMLParser(new StringReader(content));
LineNumberReader reader = new LineNumberReader(parser.getReader());
StringBuffer buffer = new StringBuffer("");
for (String line = reader.readLine(); line != null; line = reader.readLine()){
buffer.append(line);
}
String contents = buffer.toString();
document.add(new Field(DocHander.FIELD_CONTENT, contents,
Field.Store.YES, Field.Index.TOKENIZED));
return document;
}
/**
* 文檔附件建立索引
* @param article
* @param articleAttach
* @return
* @throws Exception
*/
private Document createAttachIndex(Article article, ArticleAttach articleAttach) throws Exception{
Document attachDocument = null; //注意上傳的附件,已經通過在之前被處理為byte[]形式
if (articleAttach != null && articleAttach.getFileBlob().length > 0) {
byte[] attach = articleAttach.getFileBlob();
String fileName = articleAttach.getFileName();
//採用簡單工廠模式,不同的附件格式,採用不同的DocHander,具體實現詳見下篇
DocHander docHander = DocHanderFactory.buildDocHander(fileName);
attachDocument = docHander.getDocument(attach);
attachDocument.add(new Field("fileName", articleAttach
.getFileName(), Field.Store.YES, Field.Index.TOKENIZED));
attachDocument.add(new Field("id", articleAttach.getId(),
Field.Store.YES, Field.Index.UN_TOKENIZED));
attachDocument.add(new Field("articleId", article.getId(),
Field.Store.YES, Field.Index.UN_TOKENIZED));
attachDocument.add(new Field("topic", article.getTopic(),
Field.Store.YES, Field.Index.NO));
attachDocument.add(new Field("categoryId", article.getCategoryId(),
Field.Store.YES, Field.Index.TOKENIZED));
}
return attachDocument;
}
分享到:
相关推荐
赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
赠送jar包:lucene-analyzers-common-6.6.0.jar; 赠送原API文档:lucene-analyzers-common-6.6.0-javadoc.jar; 赠送源代码:lucene-analyzers-common-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
赠送jar包:lucene-core-7.7.0.jar; 赠送原API文档:lucene-core-7.7.0-javadoc.jar; 赠送源代码:lucene-core-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.7.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-core-7.2.1.jar; 赠送原API文档:lucene-core-7.2.1-javadoc.jar; 赠送源代码:lucene-core-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.2.1.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-backward-codecs-7.3.1.jar; 赠送原API文档:lucene-backward-codecs-7.3.1-javadoc.jar; 赠送源代码:lucene-backward-codecs-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-spatial-extras-7.3.1.jar; 赠送原API文档:lucene-spatial-extras-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
赠送jar包:lucene-spatial-extras-7.2.1.jar; 赠送原API文档:lucene-spatial-extras-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-spatial-extras-6.6.0.jar; 赠送原API文档:lucene-spatial-extras-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-extras-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-backward-codecs-7.2.1.jar; 赠送原API文档:lucene-backward-codecs-7.2.1-javadoc.jar; 赠送源代码:lucene-backward-codecs-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-backward-codecs-6.6.0.jar; 赠送原API文档:lucene-backward-codecs-6.6.0-javadoc.jar; 赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-backward-codecs-6.6.0.jar; 赠送原API文档:lucene-backward-codecs-6.6.0-javadoc.jar; 赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-suggest-6.6.0.jar; 赠送原API文档:lucene-suggest-6.6.0-javadoc.jar; 赠送源代码:lucene-suggest-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-6.6.0.pom; 包含翻译后的API...
赠送jar包:lucene-highlighter-6.6.0.jar; 赠送原API文档:lucene-highlighter-6.6.0-javadoc.jar; 赠送源代码:lucene-highlighter-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-highlighter-6.6.0.pom;...
赠送jar包:lucene-core-6.6.0.jar; 赠送原API文档:lucene-core-6.6.0-javadoc.jar; 赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-sandbox-7.2.1.jar; 赠送原API文档:lucene-sandbox-7.2.1-javadoc.jar; 赠送源代码:lucene-sandbox-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-sandbox-7.2.1.pom; 包含翻译后的API...
赠送jar包:lucene-memory-6.6.0.jar; 赠送原API文档:lucene-memory-6.6.0-javadoc.jar; 赠送源代码:lucene-memory-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-memory-6.6.0.pom; 包含翻译后的API文档...
赠送jar包:lucene-suggest-7.7.0.jar; 赠送原API文档:lucene-suggest-7.7.0-javadoc.jar; 赠送源代码:lucene-suggest-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-7.7.0.pom; 包含翻译后的API...
赠送jar包:lucene-core-6.6.0.jar; 赠送原API文档:lucene-core-6.6.0-javadoc.jar; 赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-spatial-6.6.0.jar; 赠送原API文档:lucene-spatial-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-6.6.0.pom; 包含翻译后的API...