1 package org.apache.lucene.benchmark.byTask.feeds;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import java.io.Reader;
22 import java.util.Date;
25 * Parser for the GOV2 collection format
27 public class TrecGov2Parser extends TrecDocParser {
29 private static final String DATE = "Date: ";
30 private static final String DATE_END = TrecContentSource.NEW_LINE;
32 private static final String DOCHDR = "<DOCHDR>";
33 private static final String TERMINATING_DOCHDR = "</DOCHDR>";
34 private static final int TERMINATING_DOCHDR_LENGTH = TERMINATING_DOCHDR.length();
37 public DocData parse(DocData docData, String name, TrecContentSource trecSrc,
38 StringBuilder docBuf, ParsePathType pathType) throws IOException, InterruptedException {
39 // Set up a (per-thread) reused Reader over the read content, reset it to re-read from docBuf
40 Reader r = trecSrc.getTrecDocReader(docBuf);
42 // skip some of the text, optionally set date
44 int h1 = docBuf.indexOf(DOCHDR);
46 int h2 = docBuf.indexOf(TERMINATING_DOCHDR,h1);
47 String dateStr = extract(docBuf, DATE, DATE_END, h2, null);
48 if (dateStr != null) {
49 date = trecSrc.parseDate(dateStr);
51 r.mark(h2+TERMINATING_DOCHDR_LENGTH);
55 HTMLParser htmlParser = trecSrc.getHtmlParser();
56 return htmlParser.parse(docData, name, date, null, r, null);