From 7f3a4e7343207e77f7f1c327e36dc580db4b2def Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Sat, 17 Mar 2018 21:56:30 +0530 Subject: [PATCH] Fixed issue where search did not match exact the complete URL and added support for multi-word search strings --- .../restaurant/homewindow/HistoryItemController.java | 11 ++++++++--- .../restaurant/homewindow/HomeWindowController.java | 10 +++++++++- .../restaurant/util/history/HistoryManager.java | 2 -- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/rohitawate/restaurant/homewindow/HistoryItemController.java b/src/main/java/com/rohitawate/restaurant/homewindow/HistoryItemController.java index 24ab10b..7fdd6d1 100644 --- a/src/main/java/com/rohitawate/restaurant/homewindow/HistoryItemController.java +++ b/src/main/java/com/rohitawate/restaurant/homewindow/HistoryItemController.java @@ -52,10 +52,10 @@ public class HistoryItemController implements Initializable { searchString = searchString.toLowerCase(); String comparisonString; - // Checks if matches with HTTP method - comparisonString = dashboardState.getHttpMethod().toLowerCase(); + // Checks if matches with target + comparisonString = dashboardState.getTarget().toString().toLowerCase(); if (comparisonString.contains(searchString)) - return 7; + return 10; // Checks if matches with target's hostname comparisonString = dashboardState.getTarget().getHost().toLowerCase(); @@ -67,6 +67,11 @@ public class HistoryItemController implements Initializable { if (comparisonString.contains(searchString)) return 9; + // Checks if matches with HTTP method + comparisonString = dashboardState.getHttpMethod().toLowerCase(); + if (comparisonString.contains(searchString)) + return 7; + // Checks for a match in the params for (Map.Entry param : dashboardState.getParams().entrySet()) { if (param.getKey().toString().toLowerCase().contains(searchString) || diff --git a/src/main/java/com/rohitawate/restaurant/homewindow/HomeWindowController.java b/src/main/java/com/rohitawate/restaurant/homewindow/HomeWindowController.java index 57f9f7e..41afd10 100644 --- a/src/main/java/com/rohitawate/restaurant/homewindow/HomeWindowController.java +++ b/src/main/java/com/rohitawate/restaurant/homewindow/HomeWindowController.java @@ -262,7 +262,15 @@ public class HomeWindowController implements Initializable { List filteredList = new ArrayList<>(); for (HistoryItemController controller : historyItemControllers) { - if (controller.getRelativityIndex(searchString) != 0) + + int relativityIndex = 0; + + // Split the string into words and get total relativity index as sum of individual indices. + String words[] = searchString.split("\\s"); + for (String word : words) + relativityIndex += controller.getRelativityIndex(word); + + if (relativityIndex != 0) filteredList.add(controller); } diff --git a/src/main/java/com/rohitawate/restaurant/util/history/HistoryManager.java b/src/main/java/com/rohitawate/restaurant/util/history/HistoryManager.java index 71ac4b8..1307de8 100644 --- a/src/main/java/com/rohitawate/restaurant/util/history/HistoryManager.java +++ b/src/main/java/com/rohitawate/restaurant/util/history/HistoryManager.java @@ -200,8 +200,6 @@ public class HistoryManager { } } catch (SQLException e) { Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); - } finally { - System.out.println("Saved history item to database."); } }, "History Saver Thread").start();