nutch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (NUTCH-2415) Create a JEXL based IndexingFilter
Date Thu, 31 Aug 2017 09:59:00 GMT

    [ https://issues.apache.org/jira/browse/NUTCH-2415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16148758#comment-16148758
] 

ASF GitHub Bot commented on NUTCH-2415:
---------------------------------------

pipldev commented on a change in pull request #219: NUTCH-2415 : Create a JEXL based IndexingFilter
URL: https://github.com/apache/nutch/pull/219#discussion_r136294069
 
 

 ##########
 File path: src/plugin/index-jexl-filter/src/test/org/apache/nutch/indexer/filter/TestJexlIndexingFilter.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.filter;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.nutch.crawl.CrawlDatum;
+import org.apache.nutch.crawl.Inlinks;
+import org.apache.nutch.indexer.NutchDocument;
+import org.apache.nutch.metadata.Metadata;
+import org.apache.nutch.parse.Outlink;
+import org.apache.nutch.parse.ParseData;
+import org.apache.nutch.parse.ParseImpl;
+import org.apache.nutch.parse.ParseStatus;
+import org.apache.nutch.util.NutchConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJexlIndexingFilter {
+
+	@Test
+	public void testBasicIndexingFilter() throws Exception {
+		Configuration conf = NutchConfiguration.create();
+		conf.set("index.jexl.filter", "doc.lang[0]=='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", "en");
+
+		try {
+			NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"),
crawlDatum, inlinks);
+			Assert.assertNotNull(result);
+			Assert.assertEquals(doc, result);
+		} catch (Exception e) {
+			e.printStackTrace();
+			Assert.fail(e.getMessage());
+		}
+		
+		doc.removeField("lang");
+		doc.add("lang", "ru");
+		
+		try {
+			NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"),
crawlDatum, inlinks);
+			Assert.assertNull(result);
+		} catch (Exception e) {
+			e.printStackTrace();
+			Assert.fail(e.getMessage());
 
 Review comment:
   I'm not sure I understand your comment. If I understand correctly, I should just remove
the try...catch, and let the Exception be thrown, since that will fail the test with the exception.
   For the new (third) test, where we want to create an exception, I assume we should use
ExpectedException.
   Agreed?
   (BTW, all these problems with the test were also in the test you pointed me to as a template!)
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Create a JEXL based IndexingFilter
> ----------------------------------
>
>                 Key: NUTCH-2415
>                 URL: https://issues.apache.org/jira/browse/NUTCH-2415
>             Project: Nutch
>          Issue Type: New Feature
>          Components: plugin
>    Affects Versions: 1.13
>            Reporter: Yossi Tamari
>            Assignee: Jorge Luis Betancourt Gonzalez
>            Priority: Minor
>
> Following on NUTCH-2414 and NUTCH-2412, the requirement was raised for a IndexingFilter
plugin which will decide whether to index a document based on a JEXL expression.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message