| | |
| | | indexWriter.addDocuments(docs); |
| | | indexWriter.commit(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | |
| | | file.delete(); |
| | | } |
| | | |
| | | |
| | | /* |
| | | public void createdIndex(FieldSetEntity fse) throws IOException { |
| | | String function_uuid=fse.getString("function_uuid"); |
| | | String service_uuid=fse.getString("service_uuid"); |
| | | |
| | | //获取全文检索配置 |
| | | FieldSetEntity fseConfig=baseDao.getFieldSetEntityByFilter("product_sys_document_search", "function_uuid=?", new Object[] {function_uuid}, false); |
| | | if (fseConfig!=null) { |
| | | String table_uuid=fseConfig.getString("table_name"); |
| | | String attachment_field=fseConfig.getString("attachment_file"); |
| | | |
| | | //获取缓存表配置 |
| | | FieldSetEntity fseTable=baseDao.getFieldSetEntity("product_sys_datamodel_table", table_uuid, false); |
| | | if (fseTable!=null) { |
| | | |
| | | //获取原数据 |
| | | FieldSetEntity fseService=baseDao.getFieldSetEntityBySQL("SELECT * FROM "+fseTable.getString("table_name")+" WHERE uuid=?", new Object[] {service_uuid}, false); |
| | | if (fseService!=null) { |
| | | |
| | | //获取附件uuids |
| | | String attachments=fseService.getString(attachment_field); |
| | | if (!StringUtils.isEmpty(attachments)) { |
| | | |
| | | //遍历获取附件信息 |
| | | String [] attachment=attachments.split(","); |
| | | List<Document> docs=new ArrayList<>(); |
| | | for (int i = 0; i < attachment.length; i++) { |
| | | |
| | | //获取附件信息 |
| | | FieldSetEntity fseAttachment=baseDao.getFieldSetEntity("product_sys_attachments", attachment[i], false); |
| | | if (fseAttachment!=null) { |
| | | //获取附件 |
| | | File file=fileManagerService.getFile(attachment[i]); |
| | | if (file!=null) { |
| | | //生成索引信息 |
| | | Document doc=new Document(); |
| | | doc.add(new StringField("uuid", attachment[i], Field.Store.YES)); //附件UUID |
| | | doc.add(new TextField("service_uuid", service_uuid, Field.Store.YES)); //业务UUID |
| | | doc.add(new TextField("function_uuid", function_uuid, Field.Store.YES)); //共嗯那个UUID |
| | | doc.add(new TextField("file_name", fseAttachment.getString("file_name"), Field.Store.YES)); //文件名 |
| | | doc.add(new TextField("file_content", FileUtils.FileToString(file), Field.Store.YES)); //文件内内容 |
| | | docs.add(doc); |
| | | } |
| | | file.delete(); |
| | | } |
| | | } |
| | | //写入索引 |
| | | indexWriter.addDocuments(docs); |
| | | indexWriter.commit(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 文档检索 |
| | |
| | | |
| | | //分页查询文档 |
| | | TopDocs topDocs = searchByPage(fse.getInteger("cpage"), fse.getInteger("pagesize"), indexSearcher, query); |
| | | |
| | | |
| | | |
| | | ScoreDoc[] hits = topDocs.scoreDocs; |
| | | for (int i = 0; i < hits.length; i++) { |