Exemple #1
0
  public static void main(String[] args) throws ParseException, SAXException, TikaException {
    LuceneTester tester;
    try {
      tester = new LuceneTester();
      WriteFile = new WriteFile();
      Scanner scanner = new Scanner(System.in);
      // 이 machine의 JVM heap size를 출력. indexing을 하다가 OutOfMemoryError가 발생할 수 있기 때문.
      long heapSize = Runtime.getRuntime().totalMemory() / (1024 * 1024);
      System.out.println("Heap Size : " + heapSize + "MB");

      System.out.print("Index(y/n):");
      String IndexOrNot = scanner.nextLine();
      if (IndexOrNot.compareTo("y") == 0) {
        tester.createIndex();
      }
      scanner.close();
      // Setup tcpip server for query from C# front-end
      tcpIpServer = new TcpIpServer();
      tcpIpServer.setup(LuceneConstants.PORT);
      tcpIpServer.accept();
      // 쿼리가 하나 올때마다 해당하는 검색을 수행하는 루프.
      while (true) {
        String input = ""; // Query from c#
        ForSend_string = "[Search Result]\r\n"; // 실제적으로 사용하지는 아니하나, 디버깅과 검색이 완료되었다는 큐를 주기 위해 유지
        ForSend_json = new JSONObject();

        System.out.print("search query: ");
        input = tcpIpServer.read();
        // input = input.substring(1);
        System.out.println(input);
        /** ******메인 검색시에 수행 되는 서치************************ */
        if ((input.substring(0, 1).compareTo("m")) == 0) {
          // System.out.println("Main Search!" + input.substring(0, 1) +"  " + input.substring(1));
          tester.search(input.substring(1)); // search 수행
        }
        /** ******서브 검색시에 수행되는 서치************************ */
        if ((input.substring(0, 1).compareTo("s")) == 0) {
          // System.out.println("Sub Search!" + input.substring(0, 1) +"  " + input.substring(1));
          tester.sub_search(input.substring(1)); // sub-search 수행
        }
        // 검색 결과를 out.txt에 json format으로 저장. tcp전송은 큐를 날려주는 용도
        WriteFile.write(ForSend_json.toJSONString());
        tcpIpServer.write(ForSend_string);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }