aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2022-10-10 22:32:58 +0200
committerCow <cow@volloeko.de>2022-10-10 22:32:58 +0200
commit4261cab2d8056540712318586de5be4779ef49a3 (patch)
treeff9b9f2397823cd3f6e72ad0a11f2a5ce3bdab12 /src
parent693064b0a2de4030971085004c080c4bb65c1fee (diff)
downloadCowlection-4261cab2d8056540712318586de5be4779ef49a3.tar.gz
Cowlection-4261cab2d8056540712318586de5be4779ef49a3.tar.bz2
Cowlection-4261cab2d8056540712318586de5be4779ef49a3.zip
Changed `/moo search` to allow empty search queries
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/cowtipper/cowlection/search/GuiSearch.java7
-rw-r--r--src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java12
2 files changed, 9 insertions, 10 deletions
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("^\\[(?<timeHours>[\\d]{2}):(?<timeMinutes>[\\d]{2}):(?<timeSeconds>[\\d]{2})] \\[(?<thread>[^/]+)/(?<logLevel>[A-Z]+)]:(?<isChat> \\[CHAT])? (?<message>.*)$");
+ private static final Pattern LOG4J_PATTERN = Pattern.compile("^\\[(?<timeHours>\\d{2}):(?<timeMinutes>\\d{2}):(?<timeSeconds>\\d{2})] \\[(?<thread>[^/]+)/(?<logLevel>[A-Z]+)]:(?<isChat> \\[CHAT])? (?<message>.*)$");
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<Path> 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<LogEntry> 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;
}