コード例 #1
0
ファイル: Search.java プロジェクト: uwitec/outsideworld
 private List<Item> search(Query query, int num) throws Exception {
   List<Item> result = new ArrayList<Item>();
   Sort s = new Sort(new SortField("pubTime", SortField.LONG));
   TopDocs hits = indexSearcher.search(query, num, s);
   for (ScoreDoc scoreDoc : hits.scoreDocs) {
     Document doc = indexSearcher.doc(scoreDoc.doc);
     Item model = new Item();
     model.setTitle(doc.get("title"));
     model.setContent(doc.get("content"));
     model.setId(doc.get("id"));
     result.add(model);
   }
   return result;
 }
コード例 #2
0
  @SuppressWarnings("deprecation")
  @Override
  public void process(Item item) throws Exception {
    Calendar cal = Calendar.getInstance();
    String year = String.valueOf(cal.get(Calendar.YEAR));
    if (item.getTemplate() == null) {
      item.setStatus(false);
      return;
    }
    String pubTime = extract("pubTime", item);
    String tmp = "";
    Date result = new Date();
    Matcher matcher1 = regx1.matcher(pubTime);
    Matcher matcher2 = regx2.matcher(pubTime);
    Matcher matcher3 = regx3.matcher(pubTime);
    if (StringUtils.isBlank(pubTime)) {
      // 如果没有抽取到,则使用默认的抽取策略
    } else if (matcher1.find()) {
      tmp = matcher1.group();
      String[] tmps = tmp.split("-|\\s");
      tmps[0] = year;
      tmps[1] = (tmps[1].length() == 1 ? "0" + tmps[1] : tmps[1]);
      tmps[2] = (tmps[2].length() == 1 ? "0" + tmps[2] : tmps[2]);
      result = format1.parse(tmps[0] + "-" + tmps[1] + "-" + tmps[2] + " " + tmps[3]);
    } else if (matcher2.find()) {
      tmp = matcher2.group();
      String[] tmps = tmp.split("-");
      tmps[0] = year;
      tmps[1] = (tmps[1].length() == 1 ? "0" + tmps[1] : tmps[1]);
      tmps[2] = (tmps[2].length() == 1 ? "0" + tmps[2] : tmps[2]);

      result = format2.parse(tmps[0] + "-" + tmps[1] + "-" + tmps[2]);
    } else if (matcher3.find()) {
      String temp = matcher3.group();
      temp.replace("年", "-");
      temp.replace("月", "-");
      temp.replace("日", "-");
      result = new Date(temp);
    }
    item.setPubTime(result);
  }