use of org.apache.nutch.indexer.NutchDocument in project nutch by apache.
the class TestElasticIndexWriter method testBackoffPolicy.
@Test
public void testBackoffPolicy() throws IOException {
// set a non-zero "max-retry" value, **implying the cluster is saturated**
maxNumFailures = 5;
conf.setInt(ElasticConstants.EXPONENTIAL_BACKOFF_RETRIES, maxNumFailures);
int numDocs = 10;
conf.setInt(ElasticConstants.MAX_BULK_DOCS, numDocs);
Job job = Job.getInstance(conf);
testIndexWriter.setConf(conf);
testIndexWriter.open(conf, "name");
NutchDocument doc = new NutchDocument();
doc.add("id", "http://www.example.com");
// pretend the remote cluster is "saturated"
clusterSaturated = true;
Assert.assertFalse(bulkRequestSuccessful);
// write enough docs to initiate one bulk request
for (int i = 0; i < numDocs; i++) {
testIndexWriter.write(doc);
}
testIndexWriter.close();
// the BulkProcessor should have retried `maxNumFailures + 1` times, then succeeded
Assert.assertTrue(bulkRequestSuccessful);
}
use of org.apache.nutch.indexer.NutchDocument in project nutch by apache.
the class TestElasticIndexWriter method testBulkMaxLength.
@Test
public void testBulkMaxLength() throws IOException {
String key = "id";
String value = "http://www.example.com";
int defaultMaxBulkLength = conf.getInt(ElasticConstants.MAX_BULK_LENGTH, 2500500);
// Test that MAX_BULK_LENGTH is respected by lowering it 10x
int testMaxBulkLength = defaultMaxBulkLength / 10;
// This number is somewhat arbitrary, but must be a function of:
// - testMaxBulkLength
// - approximate size of each doc
int numDocs = testMaxBulkLength / (key.length() + value.length());
conf.setInt(ElasticConstants.MAX_BULK_LENGTH, testMaxBulkLength);
Job job = Job.getInstance(conf);
testIndexWriter.setConf(conf);
testIndexWriter.open(conf, "name");
NutchDocument doc = new NutchDocument();
doc.add(key, value);
Assert.assertFalse(bulkRequestSuccessful);
for (int i = 0; i < numDocs; i++) {
testIndexWriter.write(doc);
}
testIndexWriter.close();
Assert.assertTrue(bulkRequestSuccessful);
}
use of org.apache.nutch.indexer.NutchDocument in project nutch by apache.
the class TestJexlIndexingFilter method testBlockNotMatchingDocuments.
@Test
public void testBlockNotMatchingDocuments() throws Exception {
Configuration conf = NutchConfiguration.create();
conf.set("index.jexl.filter", "doc.lang=='en'");
JexlIndexingFilter filter = new JexlIndexingFilter();
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();
doc.add("lang", "ru");
NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);
Assert.assertNull(result);
}
use of org.apache.nutch.indexer.NutchDocument in project nutch by apache.
the class TestLinksIndexingFilter method testFilterInlinks.
@Test
public void testFilterInlinks() throws Exception {
conf.set(LinksIndexingFilter.LINKS_INLINKS_HOST, "true");
filter.setConf(conf);
Inlinks inlinks = new Inlinks();
inlinks.add(new Inlink("http://www.test.com", "test"));
inlinks.add(new Inlink("http://www.example.com", "example"));
NutchDocument doc = filter.filter(new NutchDocument(), new ParseImpl("text", new ParseData(new ParseStatus(), "title", new Outlink[0], metadata)), new Text("http://www.example.com/"), new CrawlDatum(), inlinks);
Assert.assertEquals(1, doc.getField("inlinks").getValues().size());
Assert.assertEquals("Filter inlinks, allow only those from a different host", "http://www.test.com", doc.getFieldValue("inlinks"));
}
use of org.apache.nutch.indexer.NutchDocument in project nutch by apache.
the class TestLinksIndexingFilter method testIndexHostsOnlyAndFilterOutlinks.
@Test
public void testIndexHostsOnlyAndFilterOutlinks() throws Exception {
conf = NutchConfiguration.create();
conf.set(LinksIndexingFilter.LINKS_ONLY_HOSTS, "true");
conf.set(LinksIndexingFilter.LINKS_OUTLINKS_HOST, "true");
Outlink[] outlinks = generateOutlinks(true);
filter.setConf(conf);
NutchDocument doc = filter.filter(new NutchDocument(), new ParseImpl("text", new ParseData(new ParseStatus(), "title", outlinks, metadata)), new Text("http://www.example.com/"), new CrawlDatum(), new Inlinks());
Assert.assertEquals(1, doc.getField("outlinks").getValues().size());
Assert.assertEquals("Index only the host portion of the outlinks after filtering", new URL("http://www.test.com").getHost(), doc.getFieldValue("outlinks"));
}
Aggregations