From 4261cab2d8056540712318586de5be4779ef49a3 Mon Sep 17 00:00:00 2001 From: Cow Date: Mon, 10 Oct 2022 22:32:58 +0200 Subject: Changed `/moo search` to allow empty search queries --- src/main/java/de/cowtipper/cowlection/search/GuiSearch.java | 7 +++---- .../de/cowtipper/cowlection/search/LogFilesSearcher.java | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/main/java/de/cowtipper') diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index 2970c24..125f155 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -27,7 +27,6 @@ import org.lwjgl.input.Keyboard; import java.awt.*; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -161,7 +160,7 @@ public class GuiSearch extends GuiScreen { boolean isStartDateValid = fieldDateStart.validateDate(); boolean isEndDateValid = fieldDateEnd.validateDate(); - this.buttonSearch.enabled = !isSearchInProgress && this.fieldSearchQuery.getText().trim().length() > 1 && !this.fieldSearchQuery.getText().startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); + this.buttonSearch.enabled = !isSearchInProgress && !this.fieldSearchQuery.getText().startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); if (isStartDateValid && isEndDateValid && dateStart.isAfter(dateEnd)) { fieldDateStart.setTextColor(0xFFDD3333); @@ -244,7 +243,7 @@ public class GuiSearch extends GuiScreen { boolean isStartDateValid = fieldDateStart.validateDate(); boolean isEndDateValid = fieldDateEnd.validateDate(); - this.buttonSearch.enabled = !isSearchInProgress && searchQuery.trim().length() > 1 && !searchQuery.startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); + this.buttonSearch.enabled = !isSearchInProgress && !searchQuery.startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); if (isStartDateValid && isEndDateValid && dateStart.isAfter(dateEnd)) { fieldDateStart.setTextColor(0xFFDD3333); @@ -508,7 +507,7 @@ public class GuiSearch extends GuiScreen { } else { // .log.gz String newLine = System.getProperty("line.separator"); String fileHeader = "# Original filename: " + logFileName + newLine + "# Use CTRL + F to search for specific words" + newLine + newLine; - try (GZIPInputStream logFileGzipped = new GZIPInputStream(new FileInputStream(logFileName)); + try (GZIPInputStream logFileGzipped = new GZIPInputStream(Files.newInputStream(searchResult.getFilePath())); FileOutputStream logFileUnGzipped = new FileOutputStream(mcLogOutputFile)) { logFileUnGzipped.write(fileHeader.getBytes()); int len; diff --git a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java index c005852..38b8202 100644 --- a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java +++ b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java @@ -26,7 +26,7 @@ class LogFilesSearcher { * - [13:33:37] [Client thread/INFO]: [CHAT] Hello World * - [08:15:42] [Client thread/ERROR]: Item entity 9001 has no item?! */ - private static final Pattern LOG4J_PATTERN = Pattern.compile("^\\[(?[\\d]{2}):(?[\\d]{2}):(?[\\d]{2})] \\[(?[^/]+)/(?[A-Z]+)]:(? \\[CHAT])? (?.*)$"); + private static final Pattern LOG4J_PATTERN = Pattern.compile("^\\[(?\\d{2}):(?\\d{2}):(?\\d{2})] \\[(?[^/]+)/(?[A-Z]+)]:(? \\[CHAT])? (?.*)$"); private int analyzedFilesWithHits = 0; LogSearchResults searchFor(String searchQuery, boolean chatOnly, boolean matchCase, boolean removeFormatting, LocalDate dateStart, LocalDate dateEnd) throws IOException { @@ -44,8 +44,8 @@ class LogFilesSearcher { } String fileName = path.getFileName().toString(); return fileName.endsWith(".log.gz") || "latest.log".equals(fileName); - }).collect(Collectors.toList()).parallelStream()) { - paths.forEach(path -> { + }); Stream allPaths = paths.collect(Collectors.toList()).parallelStream()) { + allPaths.forEach(path -> { String fileName = path.getFileName().toString(); if (fileName.endsWith("z")) { // .log.gz Matcher fileNameMatcher = LOG_FILE_PATTERN.matcher(fileName); @@ -103,8 +103,8 @@ class LogFilesSearcher { List searchResults = new ArrayList<>(); boolean foundSearchTermInFile = false; try (BufferedReader in = (isGzipped - ? new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(path.toFile())))) // ....log.gz - : new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile()))))) { // latest.log + ? new BufferedReader(new InputStreamReader(new GZIPInputStream(Files.newInputStream(path)))) // ....log.gz + : new BufferedReader(new InputStreamReader(Files.newInputStream(path))))) { // latest.log String content; LogEntry logEntry = null; while ((content = in.readLine()) != null) { @@ -172,7 +172,7 @@ class LogFilesSearcher { // no result, abort return null; } - } else if (!logMessage.contains(searchTerms)) { + } else if (searchTerms.length() > 0 && !logMessage.contains(searchTerms)) { // no result, abort return null; } -- cgit