Apache Nutch is an extensible and scalable web crawler
Index host and title in separate fields.
Douglass Cutting9b12f4062d7e
diff --git a/CHANGES.txt b/CHANGES.txtindex 49a949252..cfb82516c 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -30,6 +30,16 @@ Release 0.7redistribution by Apache. Disabled compilation of plugins whichrequire these libraries. (Doug Cutting 20050301)+ 6. Index host and title in separate fields. Host was indexed+ previously only as a part of the URL. Title was indexed as an+ anchor. Now boosts for matching these fields may be adjusted+ separately from boosts for matching anchors and url. Also: move+ site indexing to index-basic plugin to minimize the number of+ times the URL needs to be parsed; and, stop using anchor analyzer+ for anything but anchors. (Piotr Kosiorowski via Doug Cutting+ 20050323)++Release 0.61. Added clustering-carrot2 plugin, together with introduction of clusteringdiff --git a/src/java/org/apache/nutch/analysis/NutchDocumentAnalyzer.java b/src/java/org/apache/nutch/analysis/NutchDocumentAnalyzer.javaindex f5cd5044b..f69606260 100644--- a/src/java/org/apache/nutch/analysis/NutchDocumentAnalyzer.java+++ b/src/java/org/apache/nutch/analysis/NutchDocumentAnalyzer.java@@ -77,7 +77,7 @@ public class NutchDocumentAnalyzer extends Analyzer {/** Returns a new token stream for text from the named field. */public TokenStream tokenStream(String fieldName, Reader reader) {Analyzer analyzer;- if ("url".equals(fieldName) || ("anchor".equals(fieldName)))+ if ("anchor".equals(fieldName))analyzer = ANCHOR_ANALYZER;elseanalyzer = CONTENT_ANALYZER;diff --git a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.javaindex cafa1b64a..072d68773 100644--- a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java+++ b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java@@ -27,6 +27,8 @@ import org.apache.nutch.indexer.IndexingException;import org.apache.nutch.fetcher.FetcherOutput;import org.apache.nutch.pagedb.FetchListEntry;+import java.net.MalformedURLException;+import java.net.URL;import java.util.logging.Logger;import org.apache.nutch.util.LogFormatter;import org.apache.nutch.util.NutchConf;@@ -43,6 +45,21 @@ public class BasicIndexingFilter implements IndexingFilter {throws IndexingException {String url = fo.getUrl().toString();+ String host = null;+ try {+ URL u = new URL(url);+ host = u.getHost();+ } catch (MalformedURLException e) {+ throw new IndexingException(e);+ }++ if (host != null) {+ // add host as un-stored, indexed and tokenized+ doc.add(Field.UnStored("host", host));+ // add site as un-stored, indexed and un-tokenized+ doc.add(new Field("site", host, false, true, false));+ }+// url is both stored and indexed, so it's both searchable and returneddoc.add(Field.Text("url", url));@@ -61,10 +78,8 @@ public class BasicIndexingFilter implements IndexingFilter {if (title.length() > MAX_TITLE_LENGTH) { // truncate title if neededtitle = title.substring(0, MAX_TITLE_LENGTH);}- // add title as anchor so it is searchable. doesn't warrant its own field.- doc.add(Field.UnStored("anchor", title));- // add title unindexed, so that it can be displayed- doc.add(Field.UnIndexed("title", title));+ // add title indexed and stored so that it can be displayed+ doc.add(Field.Text("title", title));return doc;}diff --git a/src/plugin/query-basic/src/java/org/apache/nutch/searcher/basic/BasicQueryFilter.java b/src/plugin/query-basic/src/java/org/apache/nutch/searcher/basic/BasicQueryFilter.javaindex f39721af5..697f5d1c4 100644--- a/src/plugin/query-basic/src/java/org/apache/nutch/searcher/basic/BasicQueryFilter.java+++ b/src/plugin/query-basic/src/java/org/apache/nutch/searcher/basic/BasicQueryFilter.java@@ -36,15 +36,22 @@ public class BasicQueryFilter implements QueryFilter {private static float URL_BOOST = 4.0f;private static float ANCHOR_BOOST = 2.0f;+ private static float TITLE_BOOST = 1.5f;+ private static float HOST_BOOST = 2.0f;private static int SLOP = Integer.MAX_VALUE;private static float PHRASE_BOOST = 1.0f;- private static final String[] FIELDS = {"url", "anchor", "content"};- private static final float[] FIELD_BOOSTS = {URL_BOOST, ANCHOR_BOOST, 1.0f};+ private static final String[] FIELDS =+ { "url", "anchor", "content", "title", "host" };- /** Set the boost factor for url matches, relative to content and anchor- * matches */+ private static final float[] FIELD_BOOSTS =+ { URL_BOOST, ANCHOR_BOOST, 1.0f, TITLE_BOOST, HOST_BOOST };++ /**+ * Set the boost factor for url matches, relative to content and anchor+ * matches+ */public static void setUrlBoost(float boost) { URL_BOOST = boost; }/** Set the boost factor for title/anchor matches, relative to url anddiff --git a/src/plugin/query-site/plugin.xml b/src/plugin/query-site/plugin.xmlindex d14c3a698..faedb5da9 100755--- a/src/plugin/query-site/plugin.xml+++ b/src/plugin/query-site/plugin.xml@@ -5,10 +5,6 @@version="1.0.0"provider-name="nutch.org">- <extension-point- id="org.apache.nutch.indexer.IndexingFilter"- name="Nutch Indexing Filter"/>-<extension-pointid="org.apache.nutch.searcher.QueryFilter"name="Nutch Query Filter"/>@@ -19,14 +15,6 @@</library></runtime>- <extension id="org.apache.nutch.search.site.SiteIndexingFilter"- name="Nutch Site Indexing Filter"- point="org.apache.nutch.indexer.IndexingFilter">- <implementation id="SiteIndexingFilter"- class="org.apache.nutch.searcher.site.SiteIndexingFilter"/>- </extension>--<extension id="org.apache.nutch.searcher.site.SiteQueryFilter"name="Nutch Site Query Filter"point="org.apache.nutch.searcher.QueryFilter">diff --git a/src/plugin/query-site/src/java/org/apache/nutch/searcher/site/SiteIndexingFilter.java b/src/plugin/query-site/src/java/org/apache/nutch/searcher/site/SiteIndexingFilter.javadeleted file mode 100644index 4febb5dd7..000000000--- a/src/plugin/query-site/src/java/org/apache/nutch/searcher/site/SiteIndexingFilter.java+++ /dev/null@@ -1,60 +0,0 @@-/**- * Copyright 2005 The Apache Software Foundation- *- * Licensed 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.searcher.site;--import org.apache.lucene.document.Document;-import org.apache.lucene.document.Field;--import org.apache.nutch.parse.Parse;--import org.apache.nutch.indexer.IndexingFilter;-import org.apache.nutch.indexer.IndexingException;--import org.apache.nutch.fetcher.FetcherOutput;-import org.apache.nutch.pagedb.FetchListEntry;--import java.util.logging.Logger;-import org.apache.nutch.util.LogFormatter;--import java.net.URL;-import java.net.MalformedURLException;--/** Adds the host name to a "site" field, so that it can be searched by- * SiteQueryFilter. */-public class SiteIndexingFilter implements IndexingFilter {- public static final Logger LOG- = LogFormatter.getLogger(SiteIndexingFilter.class.getName());-- public Document filter(Document doc, Parse parse, FetcherOutput fo)- throws IndexingException {-- // parse the url to get the host name- URL url;- try {- url = new URL(fo.getUrl().toString());- } catch (MalformedURLException e) {- throw new IndexingException(e);- }-- // add host as un-stored, indexed and un-tokenized- doc.add(new Field("site", url.getHost(), false, true, false));-- // return the modified document- return doc;- }--}