354798ggg
2023-05-18 0b14e7755cf3a0d84124899f8a4ea55bafe003a2
src/main/java/com/product/lucene/service/LuceneService.java
@@ -5,10 +5,10 @@
import com.product.core.dao.BaseDao;
import com.product.core.entity.FieldSetEntity;
import com.product.core.permission.PermissionService;
import com.product.core.websocket.config.CmnConst;
import com.product.lucene.util.FileUtils;
import com.product.util.BaseUtil;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter;
@@ -95,7 +95,6 @@
                  indexWriter.addDocuments(docs);
                  indexWriter.commit();
               } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
            }
@@ -104,62 +103,6 @@
       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();
               }
            }
         }
      }
    }
*/
    
    /**
     *    文档检索
@@ -192,8 +135,6 @@
            
            //分页查询文档
            TopDocs topDocs = searchByPage(fse.getInteger("cpage"), fse.getInteger("pagesize"), indexSearcher, query);
            
            ScoreDoc[] hits = topDocs.scoreDocs;
            for (int i = 0; i < hits.length; i++) {
@@ -244,6 +185,7 @@
          
          //获取附件信息
          FieldSetEntity fseAttachment=baseDao.getFieldSetEntity("product_sys_attachments", uuid, false);
          baseDao.loadPromptData(fseAttachment);
         if (fseAttachment!=null) {
            StringBuilder filter=new StringBuilder();
            filter.append(fseAttachment.getString("attachment_data_field"));
@@ -287,6 +229,7 @@
               json.put("title", fseService.getString(fseConfig.getString("title_field")));
               json.put("function_name", fseFunction.getString("function_name"));
            }
            json.put("created_by", fseAttachment.getString(CmnConst.CREATED_BY));
         }
      }
    }