Commit 04430a7c authored by Wang Ge's avatar Wang Ge
Browse files

Restored the code and changed IndexPage

parent 0c78f9b1
Pipeline #66085 passed with stages
in 2 minutes and 12 seconds
......@@ -14,38 +14,37 @@ public class QueryProcessor {
private final String PARSER_OUTPUT_CLASS = "mw-parser-output";
public String process(String query) {
return "";
// if (query.isEmpty()) {
// return "";
// }
//
// if (query.toLowerCase().equals("bo")) {
// return "Bo is a nickname for a master of C++.\n"
// + System.lineSeparator();
// }
//
// if (query.toLowerCase().equals("pintos")) {
// return "Pintos is a very nice and easy project that every student at Imperial loves.\n"
// + System.lineSeparator();
// }
//
// Document doc;
// try {
// doc = Jsoup.connect(WIKI_URL_PREFIX + query.toLowerCase()).get();
// } catch (IOException e) {
// return "";
// }
//
// Elements parserOutputs = doc.getElementsByClass(PARSER_OUTPUT_CLASS);
// if (parserOutputs.size() == 0) {
// // can not found class
// return "";
// }
// Element parserOutput = parserOutputs.first();
// Elements contents = parserOutput.getElementsByTag("p");
// List<String> texts = contents.eachText();
//
// return findFirstParagraph(texts);
if (query.isEmpty()) {
return "";
}
if (query.toLowerCase().equals("bo")) {
return "Bo is a nickname for a master of C++.\n"
+ System.lineSeparator();
}
if (query.toLowerCase().equals("pintos")) {
return "Pintos is a very nice and easy project that every student at Imperial loves.\n"
+ System.lineSeparator();
}
Document doc;
try {
doc = Jsoup.connect(WIKI_URL_PREFIX + query.toLowerCase()).get();
} catch (IOException e) {
return "";
}
Elements parserOutputs = doc.getElementsByClass(PARSER_OUTPUT_CLASS);
if (parserOutputs.size() == 0) {
// can not found class
return "";
}
Element parserOutput = parserOutputs.first();
Elements contents = parserOutput.getElementsByTag("p");
List<String> texts = contents.eachText();
return findFirstParagraph(texts);
}
private String findFirstParagraph(List<String> texts) {
......
......@@ -18,7 +18,7 @@ public class IndexPage implements Page {
// Content
writer.println(
"<h1>Welcome!!</h1>" +
"<p>Enter your query in the box below: " +
"<p>!!!!!!Enter your query in the box below: " +
"<form>" +
"<input type=\"text\" name=\"q\" />" +
"<br>" +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment