diff --git a/src/input.txt b/src/input.txt new file mode 100644 index 0000000..32d2570 --- /dev/null +++ b/src/input.txt @@ -0,0 +1,5 @@ +라면 밀가루 달걀 밥 생선 +라면 물 소금 반죽 +첨부 봉지면 인기 +초밥 라면 밥물 채소 소금 +초밥 종류 활어 \ No newline at end of file diff --git a/src/search_engine/getSnippet.java b/src/search_engine/getSnippet.java new file mode 100644 index 0000000..6bdfbe2 --- /dev/null +++ b/src/search_engine/getSnippet.java @@ -0,0 +1,53 @@ +package search_engine; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.jsoup.Jsoup; +import org.jsoup.parser.Parser; +import org.w3c.dom.Document; + + +public class getSnippet { + + + public getSnippet(String txt, String keyword) { + try { + String fileName = "src\\" + txt; + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + Document doc = docBuilder.newDocument(); + + Path filePath = Paths.get(fileName); + InputStream inputStream = Files.newInputStream(filePath); + org.jsoup.nodes.Document readDoc = Jsoup.parse(inputStream, "UTF-8", "", Parser.xmlParser()); + + String total = readDoc.text(); + + String data[] = total.split(" "); + + System.out.println("<" + txt + " split>"); + for(int i =0 ; i < data.length ; i++) { + System.out.println(data[i]); + } + + System.out.println("\n< Է >"); + System.out.println(keyword + "\n"); + + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + +} \ No newline at end of file diff --git a/src/search_engine/kuir.java b/src/search_engine/kuir.java index 6c509cf..b4ba2bb 100644 --- a/src/search_engine/kuir.java +++ b/src/search_engine/kuir.java @@ -3,7 +3,8 @@ public class kuir { public static void main(String[] args) { - if(args.length == 2) { + + if(args.length >= 2) { if(args[0].equals("-c")) { makeCollection trigger = new makeCollection(args[1]); } @@ -13,6 +14,12 @@ else if(args[0].equals("-k")) { else if(args[0].equals("-i")) { indexer trigger = new indexer(args[1]); } + else if(args[0].equals("-s")) { + searcher trigger = new searcher(args[3], args[1]); + } + else if(args[0].equals("-f")) { + getSnippet trigger = new getSnippet(args[1], args[3]); + } else { System.out.println("\"" + args[0] + "\" ɾԴϴ."); } @@ -23,5 +30,7 @@ else if(args[0].equals("-i")) { } + + //searcher q = new searcher("鿡 , и ִ.", "index.post"); } }