Nutch and Lucene in Eclipse or Netbeans

This entry is for helping you to programme with the Nutch’s API under Netbeans (I think it will work with Eclipse).

First of all, you should download and install Nutch. There are a lot of tutorials for that. Before go to the next step you shold have something like that:

Searching with Nutch
Searching with Nutch

Now, you want to create your own class in Netbeans. Create a new proejct in Netbeans and copy that:

package ull;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.nutch.util.NutchConfiguration;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.nutch.searcher.*;

public class Buscador {

public static void main(String[] args) {
Configuration conf = NutchConfiguration.create();
NutchBean bean;
Path searchdir = new Path(“/home/ivan/Documentos/proyecto/nutch1/crawl”);
try {
conf.set(“plugin.folders”,”/home/ivan/Descargas/nutch-0.9/build/plugins”);
bean = new NutchBean(conf,searchdir);
Query query = Query.parse(“enTodos”, conf);
Hits hits = bean.search(query, 10);
System.out.println(“Total hits: ” + hits.getTotal());
int length = (int) Math.min(hits.getTotal(), 10);
Hit[] show = hits.getHits(0, length);
HitDetails[] details = bean.getDetails(show);
Summary[] summaries = bean.getSummary(details, query);

for (int i = 0; i < hits.getLength(); i++) { System.out.println(" " + i + " " + details[i] + "\n" + summaries[i]); } } catch (IOException ex) { Logger.getLogger(Buscador.class.getName()).log(Level.SEVERE, null, ex); } } } [/sourcecode] Now, you have to add Nutch.jar and after that all the jars under lib folder.Right click in Library and choose Add external jar/folder for do that. The line conf.set("plugin.folders","/home/ivan/Descargas/nutch-0.9/build/plugins"); is for determining the folder where are the plugins. I know you should modify nutch-site.xml but it didn't work for me. If you do that you will avoid the errors: java.lang.RuntimeException: org.apache.nutch.searcher.QueryFilter not found.

&

java.lang.IllegalArgumentException: plugin.folders is not defined

Thats all!

If you want to debuggin all the Nutch project you can open it installing the free-form plugin in Netbeans.

Anuncios