Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Allow LanguageIndexingFilter to actually filter documents by language.

Yossi Tamari2f7caaf760a6
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index c406907c5..05fe6912f 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -1566,6 +1566,16 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->
</description>
</property>
+<property>
+ <name>lang.index.languages</name>
+ <value></value>
+ <description>If not empty, should be a comma separated list of language codes.
+ Only documents with one of these language codes will be indexed.
+ "unknown" is a valid language code, will match documents where language
+ detection failed.
+ </description>
+</property>
+
<!-- index-static plugin properties -->
<property>
diff --git a/src/plugin/language-identifier/src/java/org/apache/nutch/analysis/lang/LanguageIndexingFilter.java b/src/plugin/language-identifier/src/java/org/apache/nutch/analysis/lang/LanguageIndexingFilter.java
index fbfe8f978..cd954c70d 100644
--- a/src/plugin/language-identifier/src/java/org/apache/nutch/analysis/lang/LanguageIndexingFilter.java
+++ b/src/plugin/language-identifier/src/java/org/apache/nutch/analysis/lang/LanguageIndexingFilter.java
@@ -27,6 +27,9 @@ import org.apache.nutch.parse.Parse;
import org.apache.nutch.metadata.Metadata;
import org.apache.nutch.net.protocols.Response;
+import java.util.HashSet;
+import java.util.Set;
+
// Hadoop imports
import org.apache.hadoop.conf.Configuration;
@@ -49,6 +52,7 @@ import org.apache.hadoop.conf.Configuration;
public class LanguageIndexingFilter implements IndexingFilter {
private Configuration conf;
+ private Set<String> indexLangs;
/**
* Constructs a new Language Indexing Filter.
@@ -73,6 +77,10 @@ public class LanguageIndexingFilter implements IndexingFilter {
lang = "unknown";
}
+ if (!indexLangs.isEmpty() && !indexLangs.contains(lang)) {
+ return null;
+ }
+
doc.add("lang", lang);
return doc;
@@ -80,6 +88,7 @@ public class LanguageIndexingFilter implements IndexingFilter {
public void setConf(Configuration conf) {
this.conf = conf;
+ indexLangs = new HashSet<>(conf.getStringCollection("lang.index.languages"));
}
public Configuration getConf() {