From aaa2ed87d4ce4458ca2c246e7a237071f9d0853c Mon Sep 17 00:00:00 2001 From: Muhammad Sayed Date: Wed, 1 Jul 2020 03:08:05 +0200 Subject: [PATCH] fix small bugs --- .../src/main/java/AddSuggestionsServlet.java | 2 +- .../main/java/FetchAllSuggestionsServlet.java | 2 +- search/src/main/java/Indexer.java | 24 +++++++++---------- search/src/main/java/QueryServlet.java | 2 +- search/src/main/java/TrendsServlet.java | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/search/src/main/java/AddSuggestionsServlet.java b/search/src/main/java/AddSuggestionsServlet.java index 2893e90..f754efc 100644 --- a/search/src/main/java/AddSuggestionsServlet.java +++ b/search/src/main/java/AddSuggestionsServlet.java @@ -44,9 +44,9 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) } } - PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); boolean result = adapter.addQuery(query); diff --git a/search/src/main/java/FetchAllSuggestionsServlet.java b/search/src/main/java/FetchAllSuggestionsServlet.java index 00d6141..ca30680 100644 --- a/search/src/main/java/FetchAllSuggestionsServlet.java +++ b/search/src/main/java/FetchAllSuggestionsServlet.java @@ -22,9 +22,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) Gson gson = new Gson(); IndexerDbAdapter adapter = new IndexerDbAdapter(); adapter.open(); - PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); ArrayList result = adapter.fetchAllQueries(); diff --git a/search/src/main/java/Indexer.java b/search/src/main/java/Indexer.java index 5902b8c..71b7020 100644 --- a/search/src/main/java/Indexer.java +++ b/search/src/main/java/Indexer.java @@ -121,18 +121,18 @@ private void HTMLParser() { * This function get last modified date stored by server **/ public String getLastModified() { - // try { - // String date = connection.execute().header("Last-Modified"); - // ArrayList dateArrayList = new ArrayList<>(); - // if (date == null) - // return "1 jan 1990"; - // else { - // dateArrayList = WordsExtractionProcess.SplitStrings(date); - // return dateArrayList.get(1) +" "+ dateArrayList.get(2) + " " + dateArrayList.get(3); - // } - // } catch (IOException e) { - // e.printStackTrace(); - // } + try { + String date = connection.execute().header("Last-Modified"); + ArrayList dateArrayList = new ArrayList<>(); + if (date == null) + return "1 jan 1990"; + else { + dateArrayList = WordsExtractionProcess.SplitStrings(date); + return dateArrayList.get(1) +" "+ dateArrayList.get(2) + " " + dateArrayList.get(3); + } + } catch (IOException e) { + e.printStackTrace(); + } return "1 jan 1990"; } diff --git a/search/src/main/java/QueryServlet.java b/search/src/main/java/QueryServlet.java index 14f46c9..1492473 100644 --- a/search/src/main/java/QueryServlet.java +++ b/search/src/main/java/QueryServlet.java @@ -20,9 +20,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) String query = request.getParameter("query"); String image = request.getParameter("img"); int page = Integer.parseInt(request.getParameter("page")); - PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); Gson gson = new Gson(); boolean isImage = (image != null && image.equals("1")) ? true : false; diff --git a/search/src/main/java/TrendsServlet.java b/search/src/main/java/TrendsServlet.java index e27eb7a..da1c716 100644 --- a/search/src/main/java/TrendsServlet.java +++ b/search/src/main/java/TrendsServlet.java @@ -22,9 +22,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) adapter.open(); String region = request.getParameter("region"); - PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); Gson gson = new Gson();