BasicIndexingFilter filter = new BasicIndexingFilter();
filter.setConf(conf);
Assert.assertNotNull(filter);
NutchDocument doc = new NutchDocument();
String title = "The Foo Page";
Outlink[] outlinks = new Outlink[] { new Outlink("http://foo.com/", "Foo") };
Metadata metaData = new Metadata();
metaData.add("Language", "en/us");
ParseData parseData = new ParseData(ParseStatus.STATUS_SUCCESS, title, outlinks, metaData);
ParseImpl parse = new ParseImpl("this is a sample foo bar page. hope you enjoy it.", parseData);
CrawlDatum crawlDatum = new CrawlDatum();
crawlDatum.setFetchTime(100L);
Inlinks inlinks = new Inlinks();
try {
filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);
} catch(Exception e){
e.printStackTrace();
Assert.fail(e.getMessage());
}
Assert.assertNotNull(doc);
Assert.assertEquals("test title, expect \"The Foo Pa\"", "The Foo Pa", doc.getField("title").getValues().get(0));
Assert.assertEquals("test domain, expect \"apache.org\"", "apache.org", doc.getField("domain").getValues().get(0));
Assert.assertEquals("test host, expect \"nutch.apache.org\"", "nutch.apache.org", doc.getField("host").getValues().get(0));
Assert.assertEquals("test url, expect \"http://nutch.apache.org/index.html\"", "http://nutch.apache.org/index.html",
doc.getField("url").getValues().get(0));
Assert.assertEquals("test content", "this is a sample foo", doc.getField("content").getValues().get(0));
Assert.assertEquals("test fetch time", new Date(100L), (Date)doc.getField("tstamp").getValues().get(0));
}