Apache Nutch is an extensible and scalable web crawler
NUTCH-1668 Remove package org.apache.nutch.indexer.solr
Julien Nioched9963f2300a0
diff --git a/CHANGES.txt b/CHANGES.txtindex 04cbb8282..fd7e1e681 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Development Trunk+* NUTCH-1668 Remove package org.apache.nutch.indexer.solr (jnioche)+* NUTCH-1621 Remove deprecated class o.a.n.crawl.Crawler (Rui Gao via jnioche)* NUTCH-656 Generic Deduplicator (jnioche, snagel)diff --git a/ivy/ivy.xml b/ivy/ivy.xmlindex 4393bc4e8..4035ff486 100644--- a/ivy/ivy.xml+++ b/ivy/ivy.xml@@ -34,11 +34,8 @@</publications><dependencies>- <dependency org="org.elasticsearch" name="elasticsearch" rev="0.90.1"- conf="*->default"/>-- <dependency org="org.apache.solr" name="solr-solrj" rev="3.4.0"- conf="*->default" />+ <dependency org="org.elasticsearch" name="elasticsearch"+ rev="0.90.1" conf="*->default" /><dependency org="org.slf4j" name="slf4j-api" rev="1.6.1"conf="*->master" />@@ -77,7 +74,8 @@<dependency org="oro" name="oro" rev="2.0.8" /><dependency org="com.google.guava" name="guava" rev="11.0.2" />- <dependency org="com.google.code.crawler-commons" name="crawler-commons" rev="0.2" />+ <dependency org="com.google.code.crawler-commons" name="crawler-commons"+ rev="0.2" /><!--Configuration: test -->diff --git a/src/bin/nutch b/src/bin/nutchindex b1c203a8d..502ffb133 100755--- a/src/bin/nutch+++ b/src/bin/nutch@@ -61,10 +61,11 @@ if [ $# = 0 ]; thenecho " invertlinks create a linkdb from parsed segments"echo " mergelinkdb merge linkdb-s, with optional filtering"echo " index run the plugin-based indexer on parsed segments and linkdb"- echo " solrindex run the solr indexer on parsed segments and linkdb"- echo " solrdedup remove duplicates from solr"- echo " solrclean remove HTTP 301 and 404 documents from solr"- echo " clean remove HTTP 301 and 404 documents from indexing backends configured via plugins"+ echo " dedup deduplicate entries in the crawldb and give them a special status"+ echo " solrindex run the solr indexer on parsed segments and linkdb - DEPRECATED use the index command instead"+ echo " solrdedup remove duplicates from solr - DEPRECATED use the dedup command instead"+ echo " solrclean remove HTTP 301 and 404 documents from solr - DEPRECATED use the clean command instead"+ echo " clean remove HTTP 301 and 404 documents and duplicates from indexing backends configured via plugins"echo " parsechecker check the parser for a given url"echo " indexchecker check the indexing filters for a given url"echo " domainstats calculate domain statistics from crawldb"@@ -226,7 +227,8 @@ elif [ "$COMMAND" = "solrindex" ] ; thenelif [ "$COMMAND" = "index" ] ; thenCLASS=org.apache.nutch.indexer.IndexingJobelif [ "$COMMAND" = "solrdedup" ] ; then- CLASS=org.apache.nutch.indexer.solr.SolrDeleteDuplicates+ echo "Command $COMMAND is deprecated, please use dedup instead"+ exit -1elif [ "$COMMAND" = "dedup" ] ; thenCLASS=org.apache.nutch.crawl.DeduplicationJobelif [ "$COMMAND" = "solrclean" ] ; thendiff --git a/src/java/org/apache/nutch/indexer/IndexingJob.java b/src/java/org/apache/nutch/indexer/IndexingJob.javaindex 7787f7bcc..8478df808 100644--- a/src/java/org/apache/nutch/indexer/IndexingJob.java+++ b/src/java/org/apache/nutch/indexer/IndexingJob.java@@ -33,7 +33,6 @@ import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.util.StringUtils;import org.apache.hadoop.util.Tool;import org.apache.hadoop.util.ToolRunner;-import org.apache.nutch.indexer.solr.SolrConstants;import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -57,14 +56,6 @@ public class IndexingJob extends Configured implements Tool {super(conf);}- public void index(Path crawlDb, Path linkDb, List<Path> segments)- throws IOException {- // SOLR SPECIFIC COMMIT PARAM USED BY CRAWL CLASS- boolean noCommit = !getConf().getBoolean(SolrConstants.COMMIT_INDEX,- true);- index(crawlDb, linkDb, segments, noCommit, false, null);- }-public void index(Path crawlDb, Path linkDb, List<Path> segments,boolean noCommit) throws IOException {index(crawlDb, linkDb, segments, noCommit, false, null);diff --git a/src/java/org/apache/nutch/indexer/solr/SolrConstants.java b/src/java/org/apache/nutch/indexer/solr/SolrConstants.javadeleted file mode 100644index 58a6328b1..000000000--- a/src/java/org/apache/nutch/indexer/solr/SolrConstants.java+++ /dev/null@@ -1,48 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package org.apache.nutch.indexer.solr;--public interface SolrConstants {- public static final String SOLR_PREFIX = "solr.";-- public static final String SERVER_URL = SOLR_PREFIX + "server.url";-- public static final String COMMIT_SIZE = SOLR_PREFIX + "commit.size";-- public static final String COMMIT_INDEX = SOLR_PREFIX + "commit.index";-- public static final String MAPPING_FILE = SOLR_PREFIX + "mapping.file";-- public static final String USE_AUTH = SOLR_PREFIX + "auth";-- public static final String USERNAME = SOLR_PREFIX + "auth.username";-- public static final String PASSWORD = SOLR_PREFIX + "auth.password";-- public static final String PARAMS = SOLR_PREFIX + "params";-- public static final String ID_FIELD = "id";-- public static final String URL_FIELD = "url";-- public static final String BOOST_FIELD = "boost";-- public static final String TIMESTAMP_FIELD = "tstamp";-- public static final String DIGEST_FIELD = "digest";--}diff --git a/src/java/org/apache/nutch/indexer/solr/SolrDeleteDuplicates.java b/src/java/org/apache/nutch/indexer/solr/SolrDeleteDuplicates.javadeleted file mode 100644index d28fa9292..000000000--- a/src/java/org/apache/nutch/indexer/solr/SolrDeleteDuplicates.java+++ /dev/null@@ -1,402 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package org.apache.nutch.indexer.solr;--import java.io.DataInput;-import java.io.DataOutput;-import java.io.IOException;-import java.net.MalformedURLException;-import java.text.SimpleDateFormat;-import java.util.Iterator;-import java.util.Date;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-import org.apache.hadoop.conf.Configuration;-import org.apache.hadoop.io.Text;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.mapred.InputFormat;-import org.apache.hadoop.mapred.InputSplit;-import org.apache.hadoop.mapred.JobClient;-import org.apache.hadoop.mapred.JobConf;-import org.apache.hadoop.mapred.OutputCollector;-import org.apache.hadoop.mapred.RecordReader;-import org.apache.hadoop.mapred.Reducer;-import org.apache.hadoop.mapred.Reporter;-import org.apache.hadoop.mapred.lib.IdentityMapper;-import org.apache.hadoop.mapred.lib.NullOutputFormat;-import org.apache.hadoop.util.Tool;-import org.apache.hadoop.util.ToolRunner;-import org.apache.nutch.util.NutchConfiguration;-import org.apache.nutch.util.NutchJob;-import org.apache.nutch.util.TimingUtil;-import org.apache.solr.client.solrj.SolrQuery;-import org.apache.solr.client.solrj.SolrServer;-import org.apache.solr.client.solrj.SolrServerException;-import org.apache.solr.client.solrj.request.UpdateRequest;-import org.apache.solr.client.solrj.response.QueryResponse;-import org.apache.solr.common.SolrDocument;-import org.apache.solr.common.SolrDocumentList;--/**- * Utility class for deleting duplicate documents from a solr index.- *- * The algorithm goes like follows:- *- * Preparation:- * <ol>- * <li>Query the solr server for the number of documents (say, N)</li>- * <li>Partition N among M map tasks. For example, if we have two map tasks- * the first map task will deal with solr documents from 0 - (N / 2 - 1) and- * the second will deal with documents from (N / 2) to (N - 1).</li>- * </ol>- *- * MapReduce:- * <ul>- * <li>Map: Identity map where keys are digests and values are {@link SolrRecord}- * instances(which contain id, boost and timestamp)</li>- * <li>Reduce: After map, {@link SolrRecord}s with the same digest will be- * grouped together. Now, of these documents with the same digests, delete- * all of them except the one with the highest score (boost field). If two- * (or more) documents have the same score, then the document with the latest- * timestamp is kept. Again, every other is deleted from solr index.- * </li>- * </ul>- *- * Note that unlike {@link DeleteDuplicate}s we assume that two documents in- * a solr index will never have the same URL. So this class only deals with- * documents with <b>different</b> URLs but the same digest.- */-public class SolrDeleteDuplicates-implements Reducer<Text, SolrDeleteDuplicates.SolrRecord, Text, SolrDeleteDuplicates.SolrRecord>,-Tool {-- public static final Logger LOG = LoggerFactory.getLogger(SolrDeleteDuplicates.class);-- private static final String SOLR_GET_ALL_QUERY = "*:*";-- private static final int NUM_MAX_DELETE_REQUEST = 1000;-- public static class SolrRecord implements Writable {-- private float boost;- private long tstamp;- private String id;-- public SolrRecord() { }-- public SolrRecord(SolrRecord old) {- this.id = old.id;- this.boost = old.boost;- this.tstamp = old.tstamp;- }-- public SolrRecord(String id, float boost, long tstamp) {- this.id = id;- this.boost = boost;- this.tstamp = tstamp;- }-- public String getId() {- return id;- }-- public float getBoost() {- return boost;- }-- public long getTstamp() {- return tstamp;- }-- public void readSolrDocument(SolrDocument doc) {- id = (String)doc.getFieldValue(SolrConstants.ID_FIELD);- boost = (Float)doc.getFieldValue(SolrConstants.BOOST_FIELD);-- Date buffer = (Date)doc.getFieldValue(SolrConstants.TIMESTAMP_FIELD);- tstamp = buffer.getTime();- }-- public void readFields(DataInput in) throws IOException {- id = Text.readString(in);- boost = in.readFloat();- tstamp = in.readLong();- }-- public void write(DataOutput out) throws IOException {- Text.writeString(out, id);- out.writeFloat(boost);- out.writeLong(tstamp);- }- }-- public static class SolrInputSplit implements InputSplit {-- private int docBegin;- private int numDocs;-- public SolrInputSplit() { }-- public SolrInputSplit(int docBegin, int numDocs) {- this.docBegin = docBegin;- this.numDocs = numDocs;- }-- public int getDocBegin() {- return docBegin;- }-- public int getNumDocs() {- return numDocs;- }-- public long getLength() throws IOException {- return numDocs;- }-- public String[] getLocations() throws IOException {- return new String[] {} ;- }-- public void readFields(DataInput in) throws IOException {- docBegin = in.readInt();- numDocs = in.readInt();- }-- public void write(DataOutput out) throws IOException {- out.writeInt(docBegin);- out.writeInt(numDocs);- }- }-- public static class SolrInputFormat implements InputFormat<Text, SolrRecord> {-- /** Return each index as a split. */- public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {- SolrServer solr = SolrUtils.getCommonsHttpSolrServer(job);-- final SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);- solrQuery.setFields(SolrConstants.ID_FIELD);- solrQuery.setRows(1);-- QueryResponse response;- try {- response = solr.query(solrQuery);- } catch (final SolrServerException e) {- throw new IOException(e);- }-- int numResults = (int)response.getResults().getNumFound();- int numDocsPerSplit = (numResults / numSplits);- int currentDoc = 0;- SolrInputSplit[] splits = new SolrInputSplit[numSplits];- for (int i = 0; i < numSplits - 1; i++) {- splits[i] = new SolrInputSplit(currentDoc, numDocsPerSplit);- currentDoc += numDocsPerSplit;- }- splits[splits.length - 1] = new SolrInputSplit(currentDoc, numResults - currentDoc);-- return splits;- }-- public RecordReader<Text, SolrRecord> getRecordReader(final InputSplit split,- final JobConf job,- Reporter reporter)- throws IOException {-- SolrServer solr = SolrUtils.getCommonsHttpSolrServer(job);- SolrInputSplit solrSplit = (SolrInputSplit) split;- final int numDocs = solrSplit.getNumDocs();-- SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);- solrQuery.setFields(SolrConstants.ID_FIELD, SolrConstants.BOOST_FIELD,- SolrConstants.TIMESTAMP_FIELD,- SolrConstants.DIGEST_FIELD);- solrQuery.setStart(solrSplit.getDocBegin());- solrQuery.setRows(numDocs);-- QueryResponse response;- try {- response = solr.query(solrQuery);- } catch (final SolrServerException e) {- throw new IOException(e);- }-- final SolrDocumentList solrDocs = response.getResults();-- return new RecordReader<Text, SolrRecord>() {-- private int currentDoc = 0;-- public void close() throws IOException { }-- public Text createKey() {- return new Text();- }-- public SolrRecord createValue() {- return new SolrRecord();- }-- public long getPos() throws IOException {- return currentDoc;- }-- public float getProgress() throws IOException {- return currentDoc / (float) numDocs;- }-- public boolean next(Text key, SolrRecord value) throws IOException {- if (currentDoc >= numDocs) {- return false;- }-- SolrDocument doc = solrDocs.get(currentDoc);- String digest = (String) doc.getFieldValue(SolrConstants.DIGEST_FIELD);- if (digest != null){- key.set(digest);- value.readSolrDocument(doc);- }-- currentDoc++;- return true;- }- };- }- }-- private Configuration conf;-- private SolrServer solr;-- private boolean noCommit = false;-- private int numDeletes = 0;-- private UpdateRequest updateRequest = new UpdateRequest();-- public Configuration getConf() {- return conf;- }-- public void setConf(Configuration conf) {- this.conf = conf;- }-- public void configure(JobConf job) {- try {- solr = SolrUtils.getCommonsHttpSolrServer(job);- noCommit = job.getBoolean("noCommit", false);- } catch (MalformedURLException e) {- throw new RuntimeException(e);- }- }--- public void close() throws IOException {- try {- if (numDeletes > 0) {- LOG.info("SolrDeleteDuplicates: deleting " + numDeletes + " duplicates");- updateRequest.process(solr);-- if (!noCommit) {- solr.commit();- }- }- } catch (SolrServerException e) {- throw new IOException(e);- }- }-- public void reduce(Text key, Iterator<SolrRecord> values,- OutputCollector<Text, SolrRecord> output, Reporter reporter)- throws IOException {- SolrRecord recordToKeep = new SolrRecord(values.next());- while (values.hasNext()) {- SolrRecord solrRecord = values.next();- if (solrRecord.getBoost() > recordToKeep.getBoost() ||- (solrRecord.getBoost() == recordToKeep.getBoost() &&- solrRecord.getTstamp() > recordToKeep.getTstamp())) {- updateRequest.deleteById(recordToKeep.id);- recordToKeep = new SolrRecord(solrRecord);- } else {- updateRequest.deleteById(solrRecord.id);- }- numDeletes++;- reporter.incrCounter("SolrDedupStatus", "Deleted documents", 1);- if (numDeletes >= NUM_MAX_DELETE_REQUEST) {- try {- LOG.info("SolrDeleteDuplicates: deleting " + numDeletes + " duplicates");- updateRequest.process(solr);- } catch (SolrServerException e) {- throw new IOException(e);- }- updateRequest = new UpdateRequest();- numDeletes = 0;- }- }- }-- public void dedup(String solrUrl) throws IOException {- dedup(solrUrl, false);- }-- public void dedup(String solrUrl, boolean noCommit) throws IOException {- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");- long start = System.currentTimeMillis();- LOG.info("SolrDeleteDuplicates: starting at " + sdf.format(start));- LOG.info("SolrDeleteDuplicates: Solr url: " + solrUrl);-- JobConf job = new NutchJob(getConf());-- job.set(SolrConstants.SERVER_URL, solrUrl);- job.setBoolean("noCommit", noCommit);- job.setInputFormat(SolrInputFormat.class);- job.setOutputFormat(NullOutputFormat.class);- job.setMapOutputKeyClass(Text.class);- job.setMapOutputValueClass(SolrRecord.class);- job.setMapperClass(IdentityMapper.class);- job.setReducerClass(SolrDeleteDuplicates.class);-- JobClient.runJob(job);-- long end = System.currentTimeMillis();- LOG.info("SolrDeleteDuplicates: finished at " + sdf.format(end) + ", elapsed: " + TimingUtil.elapsedTime(start, end));- }-- public int run(String[] args) throws IOException {- if (args.length < 1) {- System.err.println("Usage: SolrDeleteDuplicates <solr url> [-noCommit]");- return 1;- }-- boolean noCommit = false;- if (args.length == 2 && args[1].equals("-noCommit")) {- noCommit = true;- }-- dedup(args[0], noCommit);- return 0;- }-- public static void main(String[] args) throws Exception {- int result = ToolRunner.run(NutchConfiguration.create(),- new SolrDeleteDuplicates(), args);- System.exit(result);- }--}diff --git a/src/java/org/apache/nutch/indexer/solr/SolrUtils.java b/src/java/org/apache/nutch/indexer/solr/SolrUtils.javadeleted file mode 100644index b53082528..000000000--- a/src/java/org/apache/nutch/indexer/solr/SolrUtils.java+++ /dev/null@@ -1,76 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package org.apache.nutch.indexer.solr;--import org.apache.commons.httpclient.HttpClient;-import org.apache.commons.httpclient.auth.AuthScope;-import org.apache.commons.httpclient.UsernamePasswordCredentials;-import org.apache.commons.httpclient.params.HttpClientParams;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-import org.apache.hadoop.mapred.JobConf;-import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;--import java.net.MalformedURLException;--public class SolrUtils {-- public static Logger LOG = LoggerFactory.getLogger(SolrUtils.class);-- public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {- HttpClient client=new HttpClient();-- // Check for username/password- if (job.getBoolean(SolrConstants.USE_AUTH, false)) {- String username = job.get(SolrConstants.USERNAME);-- LOG.info("Authenticating as: " + username);-- AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);-- client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));-- HttpClientParams params = client.getParams();- params.setAuthenticationPreemptive(true);-- client.setParams(params);- }-- return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);- }-- public static String stripNonCharCodepoints(String input) {- StringBuilder retval = new StringBuilder();- char ch;-- for (int i = 0; i < input.length(); i++) {- ch = input.charAt(i);-- // Strip all non-characters http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Noncharacter_Code_Point=True:]- // and non-printable control characters except tabulator, new line and carriage return- if (ch % 0x10000 != 0xffff && // 0xffff - 0x10ffff range step 0x10000- ch % 0x10000 != 0xfffe && // 0xfffe - 0x10fffe range- (ch <= 0xfdd0 || ch >= 0xfdef) && // 0xfdd0 - 0xfdef- (ch > 0x1F || ch == 0x9 || ch == 0xa || ch == 0xd)) {-- retval.append(ch);- }- }-- return retval.toString();- }-}