From 4b8d2a781442df8924a19eb46fcac3d500e05679 Mon Sep 17 00:00:00 2001 From: jiaoliming Date: Fri, 1 Sep 2023 10:07:22 +0800 Subject: [PATCH] =?UTF-8?q?rev=EF=BC=9Alucene?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaoliming --- .../lucene/common/LuceneIndexWriter.java | 132 +++++++++--------- .../nl/modules/lucene/common/Searcher.java | 4 +- .../lucene/service/dto/LuceneLogDto.java | 17 +++ .../impl/LuceneExecuteLogServiceImpl.java | 4 +- 4 files changed, 87 insertions(+), 70 deletions(-) diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java index d4e89056..fb9451d2 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java @@ -1,66 +1,66 @@ -package org.nl.modules.lucene.common; - -import cn.hutool.core.date.DateUtil; -import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.store.Directory; -import org.apache.lucene.store.FSDirectory; -import org.nl.modules.lucene.config.UrlConfig; -import org.wltea.analyzer.lucene.IKAnalyzer; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class LuceneIndexWriter { - private static volatile IndexWriter indexWriter; - - static { - try { - Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath()); - IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer()); - indexWriter = new IndexWriter(directory, config); - } catch (Exception e) { - e.printStackTrace(); - } - /**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/ -// Runtime.getRuntime().addShutdownHook(new Thread(){ -// @Override -// public void run() { -// try { -// closeIndexWriter(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// }); - } - /**在线程结束时,自动关闭IndexWriter*/ - public static IndexWriter getIndexWriter() { - return indexWriter; - } - /**关闭IndexWriter - * @throws IOException - * @throws CorruptIndexException */ - public static void closeIndexWriter() throws Exception { - if(indexWriter != null) { -// indexWriter.close(); - } - } - - public static void main(String[] args) throws IOException { - indexWriter.deleteAll(); - } - - public static String getDate(String timeString) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");//时间格式 - Date date = sdf.parse(timeString); - timeString = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss.SSS");//格式化后的时间 - return timeString; - } - - -} +//package org.nl.modules.lucene.common; +// +//import cn.hutool.core.date.DateUtil; +//import org.apache.lucene.index.CorruptIndexException; +//import org.apache.lucene.index.IndexWriter; +//import org.apache.lucene.index.IndexWriterConfig; +//import org.apache.lucene.store.Directory; +//import org.apache.lucene.store.FSDirectory; +//import org.nl.modules.lucene.config.UrlConfig; +//import org.wltea.analyzer.lucene.IKAnalyzer; +// +//import java.io.File; +//import java.io.IOException; +//import java.text.ParseException; +//import java.text.SimpleDateFormat; +//import java.util.Date; +// +//public class LuceneIndexWriter { +// private static volatile IndexWriter indexWriter; +// +// static { +// try { +// Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath()); +// IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer()); +// indexWriter = new IndexWriter(directory, config); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// /**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/ +//// Runtime.getRuntime().addShutdownHook(new Thread(){ +//// @Override +//// public void run() { +//// try { +//// closeIndexWriter(); +//// } catch (Exception e) { +//// e.printStackTrace(); +//// } +//// } +//// }); +// } +// /**在线程结束时,自动关闭IndexWriter*/ +// public static IndexWriter getIndexWriter() { +// return indexWriter; +// } +// /**关闭IndexWriter +// * @throws IOException +// * @throws CorruptIndexException */ +// public static void closeIndexWriter() throws Exception { +// if(indexWriter != null) { +//// indexWriter.close(); +// } +// } +// +// public static void main(String[] args) throws IOException { +// indexWriter.deleteAll(); +// } +// +// public static String getDate(String timeString) throws ParseException { +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");//时间格式 +// Date date = sdf.parse(timeString); +// timeString = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss.SSS");//格式化后的时间 +// return timeString; +// } +// +// +//} diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java index 140c96e5..ae027a4c 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java @@ -58,12 +58,12 @@ public class Searcher { if (startDate == null){ startDate = DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH:mm:ss.SSS"); }else{ - startDate = LuceneIndexWriter.getDate(startDate); + startDate = LuceneServiceAutoRun.getDate(startDate); } if (endDate == null){ endDate = DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss.SSS"); } else { - endDate = LuceneIndexWriter.getDate(endDate); + endDate = LuceneServiceAutoRun.getDate(endDate); } TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true); booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST); diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java index 57cdcea3..bed52ce9 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java @@ -91,4 +91,21 @@ public class LuceneLogDto { + "] : " + remark; } + + public LuceneLogDto(final String device_code, final String item, final int last_info, + final int info) { + super(); + String info_china = ""; + switch(info){ + case 0: info_china = "未联机"; + case 1: info_china = "已联机"; + case 2: break; + default:; + } + this.device_code = device_code; + this.content = "信号 [" + +item + "] 发生变更 " + + last_info + " -> " + + info; + } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java index c1fd06cd..b8dff032 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java @@ -10,7 +10,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.index.IndexWriter; -import org.nl.modules.lucene.common.LuceneIndexWriter; +import org.nl.modules.lucene.common.LuceneServiceAutoRun; import org.nl.modules.lucene.enums.LogTypeEnum; import org.nl.modules.lucene.service.LuceneExecuteLogService; import org.nl.modules.lucene.service.dto.LuceneLogDto; @@ -48,7 +48,7 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService { } private void addIndex(LuceneLogDto luceneLogDto) throws IOException { - IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter(); + IndexWriter indexWriter = LuceneServiceAutoRun.getIndexWriter(); //创建一个Document对象 Document document = new Document(); try {