Ejemplo n.º 1
0
 public String getElapsedTime() {
   if (isRunning()) {
     return Formatter.getFormatTime(System.currentTimeMillis() - startTime);
   } else if (isFinished()) {
     return Formatter.getFormatTime(endTime - startTime);
   } else {
     return "";
   }
 }
  @Override
  public void writeResult(Object obj, long searchTime, boolean isSuccess)
      throws ResultWriterException, IOException {
    if (!isSuccess) {
      String errorMsg = null;
      if (obj == null) {
        errorMsg = "null";
      } else {
        errorMsg = obj.toString();
      }
      resultWriter
          .object()
          .key("status")
          .value(1)
          .key("time")
          .value(Formatter.getFormatTime(searchTime))
          .key("total_count")
          .value(0)
          .key("error_msg")
          .value(errorMsg)
          .endObject();
    } else {
      Result result = (Result) obj;

      //			fieldNames = result.getFieldNameList();
      resultWriter
          .object()
          .key("status")
          .value(0)
          .key("time")
          .value(Formatter.getFormatTime(searchTime))
          .key("start")
          .value(result.getStart())
          .key("total_count")
          .value(result.getTotalCount())
          .key("count")
          .value(result.getCount());
      //			.key("field_count").value(fieldNames.length)
      //			.key("fieldname_list")
      //			.array("name");
      //
      //			for (int i = 0; i < fieldNames.length; i++) {
      //				resultWriter.value(fieldNames[i]);
      //			}
      //			resultWriter.endArray();
      writeBody(result, resultWriter, searchTime);
      resultWriter.endObject();

      resultWriter.done();
    }
  }
  public void compile(File input, String charset, File output) throws IRException {
    long st = System.currentTimeMillis();
    try {
      logger.info("SpecialCharacterMap compile start!");
      BufferedReader br =
          new BufferedReader(new InputStreamReader(new FileInputStream(input), charset));
      IndexOutput out = new BufferedFileOutput(output);
      String line = null;
      int cnt = 0;
      while ((line = br.readLine()) != null) {
        String[] str = line.split(",");
        for (int i = 0; i < str.length; i++) {
          int ch = Integer.parseInt(str[i], 16);

          //					if(cnt % 16 == 0)
          //						System.out.println();
          //					System.out.println(cnt+" = "+(char)ch+"/ "+(char)cnt);
          //
          //					if(cnt > 300)
          //						break;

          out.writeUChar(ch);
          cnt++;
        }

        //				if(cnt > 300)
        //					break;
      }
      out.flush();
      out.close();
      br.close();
      logger.info(
          "SpecialCharacterMap compile done.. total {} word. {}",
          cnt,
          Formatter.getFormatTime(System.currentTimeMillis() - st));
    } catch (FileNotFoundException e) {
      logger.error("FileNotFoundException", e);
      throw new IRException(e);
    } catch (IOException e) {
      logger.error("IOException", e);
      throw new IRException(e);
    }
  }