Network setting in Ubuntu server 12.10
sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
netmask 255.255.255.0
broadcast 10.1.62.255
auto eth1
iface eth1 inet dhcp
netmask 255.255.255.0
broadcast 10.1.62.255
sudo service networking restart
sudo ifup eth0
sudo ifup eth1
ifconfig -a
will see the results of configuration
eth0 with ip 10.1.62.xxx
eth1 with ip 192.168.2.99
to test ping google.com
Thursday, October 25, 2012
Monday, October 1, 2012
Building a Java Application with Nutch 2.0 and Solr 3.6
Apache Nutch 2.0 source @ ~/tmp/apache-solr-3.6.0 SOLR_HOME
Apache Solr 3.6 binary @ ~/tmp/apache-nutch-2.0-src NUTCH_HOME
Apache hbase @ ~/tmp/hbase-0.90.6 HBASE_HOME
1. Preparing libraries in Eclipse
Go to /path/to/solr/dist and open apache-solr-3.6.0.war with your favorite archive manager. Go to /WEB-INF/lib/ and extract everything there to /path/to/solr/dist. This will allow us to include all the libraries we need in our Java application.
2. Creating an Eclipse project
Create a Java project with a class called MyCrawler.
Add a lib folder into the project, then add two sub folders: nutch and solr. Copy everything from NUTCH_HOME/lib to lib/nutch and everything from SOLR_HOME/dist to lib/solr.
Add a plugins folder into the project, add everything from NUTCH_HOME/plugins to it.
Add a urls folder and create a seed.txt file. Put seed urls here.
Create two folders somewhere on the file system: nutchconf and solrconf, and copy all the files from NUTCH_HOME/conf and SOLR_HOME/example/solr/conf to them respectively.
In Eclipse project properties->Java Build Path, click on Add Class folder and add nutchconf and solrconf folders in. Go to Order and Export, find the entries for nutchConf and solrConf and move them to the top.
Change Lucene_core_3.4.0.jar to Lucene_core_3.6.0.jar.
Change Lucene_core_3.4.0.jar to Lucene_core_3.6.0.jar.
3. Adding code into MyCrawler.
4. Run.
start hbase
start solr
run MyCrawler as Java application
Other resources:
package websearch.crawler;
import java.util.StringTokenizer;
import org.apache.hadoop.util.ToolRunner;
import org.apache.nutch.indexer.solr.SolrIndexerJob;
import org.apache.nutch.crawl.Crawler;
import org.apache.nutch.util.NutchConfiguration;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
public class MyCrawler {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String crawlArg = "urls -depth 3 -topN 5";
// Run Crawl tool
try {
ToolRunner.run(NutchConfiguration.create(), new Crawler(),
tokenize(crawlArg));
} catch (Exception e) {
e.printStackTrace();
return;
}
String indexArg = "http://localhost:8983/solr -reindex";
//Run Solr index tool
try {
ToolRunner.run(NutchConfiguration.create(), new SolrIndexerJob(),
tokenize(indexArg));
} catch (Exception e) {
e.printStackTrace();
return;
}
// Let's query for something!
String url = "http://localhost:8983/solr";
CommonsHttpSolrServer server = new CommonsHttpSolrServer( url );
SolrQuery query = new SolrQuery();
query.setQuery("content:mycontent"); // Searching mycontent in query
query.addSortField("content", SolrQuery.ORDER.asc);
QueryResponse rsp;
try {
rsp = server.query(query);
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
// Display the results in the console
SolrDocumentList docs = rsp.getResults();
for (int i = 0; i < docs.size(); i++) {
System.out.println(docs.get(i).get("title").toString() + " Link: "
+ docs.get(i).get("url").toString());
}
}
/**
* Helper function to convert a string into an array of strings by
* separating them using whitespace.
*
* @param str
* string to be tokenized
* @return an array of strings that contain a each word each
*/
public static String[] tokenize(String str) {
StringTokenizer tok = new StringTokenizer(str);
String tokens[] = new String[tok.countTokens()];
int i = 0;
while (tok.hasMoreTokens()) {
tokens[i] = tok.nextToken();
i++;
}
return tokens;
}
}
4. Run.
start hbase
start solr
run MyCrawler as Java application
Other resources:
- Building a Java application with Apache Nutch and Solr
- Solr Wiki: http://wiki.apache.org/solr/Solrj
- http://lucidworks.lucidimagination.com/display/solr/Using+SolrJ
- regex checker: http://regexpal.com/
Tuesday, September 25, 2012
Nutch Gora HBase Solr
1. download Nutch 2.0
2. download HBase version 0.90.6, nutch 2.0 doesn't work with higher version.
follow instructions for installation http://hbase.apache.org/book/quickstart.html
note: if there is a proxy interface setting error, then change localhost/127.0.0.1 to IP address at /etc/hosts; if running in a virtual machine, then change IP address of the virtual host.
3. follow tutorials at http://wiki.apache.org/nutch/Nutch2Tutorial
nutch-site.xml
<property>
<name>http.agent.name</name>
<value>Spider</value>
</property>
<property>
<name>http.robots.agents</name>
<value>Spider,*</value>
</property>
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.hbase.store.HBaseStore</value>
<description>Default class for storing data</description>
</property>
<property>
<name>http.content.limit</name>
<value>-1</value>
</property>
<property>
<name>plugin.includes</name>
<value>protocol-http|urlfilter-regex|parse-(html|tika|text)|index-(basic|anchor)|query-(basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
</property>
ivy/ivy.xml
gora.properties
4. ant build
build files are in /runtime
5. follow instructions of nutch 1.5 and solr
bin/nutch crawl urls -depth 3 -topN 5 (this stores results in hbase but does not index in Solr)
6. after running nutch, all files are stored in hbase /webpage
bin/hbase shell
hbase(main):002:0> scan "webpage"
2. download HBase version 0.90.6, nutch 2.0 doesn't work with higher version.
follow instructions for installation http://hbase.apache.org/book/quickstart.html
note: if there is a proxy interface setting error, then change localhost/127.0.0.1 to IP address at /etc/hosts; if running in a virtual machine, then change IP address of the virtual host.
3. follow tutorials at http://wiki.apache.org/nutch/Nutch2Tutorial
nutch-site.xml
<property>
<name>http.agent.name</name>
<value>Spider</value>
</property>
<property>
<name>http.robots.agents</name>
<value>Spider,*</value>
</property>
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.hbase.store.HBaseStore</value>
<description>Default class for storing data</description>
</property>
<property>
<name>http.content.limit</name>
<value>-1</value>
</property>
<property>
<name>plugin.includes</name>
<value>protocol-http|urlfilter-regex|parse-(html|tika|text)|index-(basic|anchor)|query-(basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
</property>
ivy/ivy.xml
<!-- Uncomment this to use HBase as Gora backend. -->
<dependency org="org.apache.gora" name="gora-hbase" rev="0.2" conf="*->default" />
gora.properties
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
4. ant build
build files are in /runtime
5. follow instructions of nutch 1.5 and solr
bin/nutch crawl urls -depth 3 -topN 5 (this stores results in hbase but does not index in Solr)
to index in Solr bin/nutch solrindex http://localhost:8983/solr -reindex
6. after running nutch, all files are stored in hbase /webpage
bin/hbase shell
hbase(main):002:0> scan "webpage"
Friday, September 21, 2012
Eclipse installation on Ubuntu
1. download and extract.
2.
sudo mv eclipse /opt/
cd /opt/eclipse
sudo chown -R root:root eclipse
sudo chmod -R +r eclipse
3. Create an eclipse executable in your path
2.
sudo mv eclipse /opt/
cd /opt/eclipse
sudo chown -R root:root eclipse
sudo chmod -R +r eclipse
3. Create an eclipse executable in your path
sudo touch /usr/bin/eclipse
sudo chmod 755 /usr/bin/eclipse
sudo nano /usr/bin/eclipse
copy this into nano
#!/bin/sh
#export MOZILLA_FIVE_HOME="/usr/lib/mozilla/"
export ECLIPSE_HOME="/opt/eclipse"
$ECLIPSE_HOME/eclipse $*
4. Create a gnome menu item
sudo nano /usr/share/applications/eclipse.desktop
copy this into nano
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=eclipse
Icon=/opt/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true
save and exit nano
6) Launch Eclipse for the first time
/opt/eclipse/eclipse -clean &
Thursday, September 20, 2012
Solr Query
default for all *:*, : used to separate parameters and values,e.g.
keywords:web
Using AND (&&), OR
content: OWL OR title: Semantic Web
content: OWL && title: Semantic Web
content: OWL AND title: Semantic Web
Nested Queries
using _query_
content:"semantic" AND _query_:"alcategory:computer_internet" AND _query_:"title:web" AND _query_:"keywords:data"
source: http://searchhub.org/dev/2009/03/31/nested-queries-in-solr/
keywords:web
Using AND (&&), OR
content: OWL OR title: Semantic Web
content: OWL && title: Semantic Web
content: OWL AND title: Semantic Web
Nested Queries
using _query_
content:"semantic" AND _query_:"alcategory:computer_internet" AND _query_:"title:web" AND _query_:"keywords:data"
source: http://searchhub.org/dev/2009/03/31/nested-queries-in-solr/
Wednesday, September 19, 2012
Crawling PDF using Apache Nutch
Nutch uses pdfbox plugin for crawling pdf documents. The plugin is located in /plugins/parse-tika
in nutch-site.xml
add:
<property>
<name>http.content.size</name>
<value>-1</value>
</property>
<property>
<name>plugin.includes</name>
<value>protocol-http|urlfilter-regex|parse-(html|tika|text)|index-(basic|anchor)|que
ry-(basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlno
rmalizer-(pass|regex|basic)</value>
</property>
testing using url: http://www.master.netseven.it/files/262-Nutch.pdf
note:
parsed with unreadable symbols for pdf files converted from Microsoft Word. example URL: http://clgiles.ist.psu.edu/IST441/materials/nutch-lucene/nutch-crawling-and-searching.pdf
in nutch-site.xml
add:
<property>
<name>http.content.size</name>
<value>-1</value>
</property>
<property>
<name>plugin.includes</name>
<value>protocol-http|urlfilter-regex|parse-(html|tika|text)|index-(basic|anchor)|que
ry-(basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlno
rmalizer-(pass|regex|basic)</value>
</property>
testing using url: http://www.master.netseven.it/files/262-Nutch.pdf
note:
parsed with unreadable symbols for pdf files converted from Microsoft Word. example URL: http://clgiles.ist.psu.edu/IST441/materials/nutch-lucene/nutch-crawling-and-searching.pdf
Delete Documents from Solr index
Delete all documents from Solr index, enter the following in browser:
http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete> http://localhost:8983/solr/update?stream.body=<commit/>
Subscribe to:
Posts (Atom)