~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DemoHTMLParser.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.benchmark.byTask.feeds;
2
 
 
3
 
/**
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
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
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.
18
 
 */
19
 
 
20
 
import java.io.IOException;
21
 
import java.io.Reader;
22
 
import java.text.DateFormat;
23
 
import java.text.ParseException;
24
 
import java.util.Date;
25
 
import java.util.Properties;
26
 
 
27
 
/**
28
 
 * HTML Parser that is based on Lucene's demo HTML parser.
29
 
 */
30
 
public class DemoHTMLParser implements org.apache.lucene.benchmark.byTask.feeds.HTMLParser {
31
 
 
32
 
  public DocData parse(DocData docData, String name, Date date, String title, Reader reader, DateFormat dateFormat) throws IOException, InterruptedException {
33
 
    org.apache.lucene.benchmark.byTask.feeds.demohtml.HTMLParser p = new org.apache.lucene.benchmark.byTask.feeds.demohtml.HTMLParser(reader);
34
 
    
35
 
    // title
36
 
    if (title==null) {
37
 
      title = p.getTitle();
38
 
    }
39
 
    
40
 
    // properties 
41
 
    Properties props = p.getMetaTags(); 
42
 
    // body
43
 
    Reader r = p.getReader();
44
 
    char c[] = new char[1024];
45
 
    StringBuilder bodyBuf = new StringBuilder();
46
 
    int n;
47
 
    while ((n = r.read(c)) >= 0) {
48
 
      if (n>0) {
49
 
        bodyBuf.append(c,0,n);
50
 
      }
51
 
    }
52
 
    r.close();
53
 
    if (date == null && props.getProperty("date")!=null) {
54
 
      try {
55
 
        date = dateFormat.parse(props.getProperty("date").trim());
56
 
      } catch (ParseException e) {
57
 
        // do not fail test just because a date could not be parsed
58
 
        System.out.println("ignoring date parse exception (assigning 'now') for: "+props.getProperty("date"));
59
 
        date = new Date(); // now 
60
 
      }
61
 
    }
62
 
    
63
 
    docData.clear();
64
 
    docData.setName(name);
65
 
    docData.setBody(bodyBuf.toString());
66
 
    docData.setTitle(title);
67
 
    docData.setProps(props);
68
 
    docData.setDate(date);
69
 
    return docData;
70
 
  }
71
 
 
72
 
}