| 1 |
|
package org.apache.lucene.demo; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import java.io.*; |
| 20 |
|
import org.apache.lucene.document.*; |
| 21 |
|
import org.apache.lucene.demo.html.HTMLParser; |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 25 |
|
public class HTMLDocument { |
| 26 |
|
static char dirSep = System.getProperty("file.separator").charAt(0); |
| 27 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 28 |
0
|
public static String uid(File f) {... |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
0
|
return f.getPath().replace(dirSep, '\u0000') + |
| 34 |
|
"\u0000" + |
| 35 |
|
DateTools.timeToString(f.lastModified(), DateTools.Resolution.SECOND); |
| 36 |
|
} |
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 38 |
0
|
public static String uid2url(String uid) {... |
| 39 |
0
|
String url = uid.replace('\u0000', '/'); |
| 40 |
0
|
return url.substring(0, url.lastIndexOf('/')); |
| 41 |
|
} |
| 42 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 43 |
0
|
public static Document Document(File f)... |
| 44 |
|
throws IOException, InterruptedException { |
| 45 |
|
|
| 46 |
0
|
Document doc = new Document(); |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
0
|
doc.add(new Field("path", f.getPath().replace(dirSep, '/'), Field.Store.YES, |
| 51 |
|
Field.Index.UN_TOKENIZED)); |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
0
|
doc.add(new Field("modified", |
| 57 |
|
DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE), |
| 58 |
|
Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
0
|
doc.add(new Field("uid", uid(f), Field.Store.NO, Field.Index.UN_TOKENIZED)); |
| 64 |
|
|
| 65 |
0
|
FileInputStream fis = new FileInputStream(f); |
| 66 |
0
|
HTMLParser parser = new HTMLParser(fis); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
0
|
doc.add(new Field("contents", parser.getReader())); |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
0
|
doc.add(new Field("summary", parser.getSummary(), Field.Store.YES, Field.Index.NO)); |
| 75 |
|
|
| 76 |
|
|
| 77 |
0
|
doc.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.TOKENIZED)); |
| 78 |
|
|
| 79 |
|
|
| 80 |
0
|
return doc; |
| 81 |
|
} |
| 82 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 83 |
0
|
private HTMLDocument() {}... |
| 84 |
|
} |
| 85 |
|
|