Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

removed unneeded SearchContext

Sami Siren635fa2c9a8bd
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
index 3d5b7ca82..a59a0157a 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
@@ -64,8 +64,6 @@ public class BaseSearch {
}
- private SearchContextImpl context;
-
private ServiceLocator serviceLocator;
/**
@@ -114,9 +112,9 @@ public class BaseSearch {
/**
* Call plugins participating PreSearch activities
*/
- void callPreSearch() {
+ void callPreSearch(ServiceLocator locator) {
for (int i = 0; i < presearch.length; i++) {
- presearch[i].doPreSearch(context);
+ presearch[i].doPreSearch(serviceLocator);
}
}
@@ -125,16 +123,16 @@ public class BaseSearch {
*/
void callSearch() {
for (int i = 0; i < search.length; i++) {
- search[i].doSearch(context);
+ search[i].doSearch(serviceLocator);
}
}
/**
* Call plugins participating postSearch activities
*/
- void callPostSearch() {
+ void callPostSearch(ServiceLocator locator) {
for (int i = 0; i < postsearch.length; i++) {
- postsearch[i].doPostSearch(context);
+ postsearch[i].doPostSearch(serviceLocator);
}
}
@@ -143,10 +141,9 @@ public class BaseSearch {
*/
public void doSearch() {
// create context
- context = new SearchContextImpl(serviceLocator);
- callPreSearch();
+ callPreSearch(serviceLocator);
serviceLocator.getSearch().performSearch();
// callSearch();
- callPostSearch();
+ callPostSearch(serviceLocator);
}
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
index 919aee534..8b7ce5d5d 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
@@ -88,8 +88,15 @@ public class Search {
LOG.info("performing search, requiring:" + getHitsRequired());
try {
+ LOG.info("query:" + getQuery());
+ LOG.info("endOffset:" + getStartOffset() + getHitsRequired());
+ LOG.info("hitsPerDup:" + getHitsPerDup());
+ LOG.info("dupField:" + getDupField());
+ LOG.info("sortField:" + getSortColumn());
+ LOG.info("descending:" + isSortDesc());
+
hits = locator.getNutchBean().search(getQuery(), getStartOffset() + getHitsRequired(),
- getHitsPerSite(), getDupField(), getSortColumn(), isSortDesc());
+ getHitsPerDup(), getDupField(), getSortColumn(), isSortDesc());
} catch (IOException e) {
hits = new Hits(0, new Hit[0]);
}
@@ -202,7 +209,7 @@ public class Search {
/**
* @return Returns the hitsPerSite.
*/
- public int getHitsPerSite() {
+ public int getHitsPerDup() {
return hitsPerDup;
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContext.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContext.java
deleted file mode 100644
index 83af99ed5..000000000
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContext.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2006 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.webapp.common;
-
-import org.apache.hadoop.conf.Configuration;
-
-/**
- * SearchContext
- */
-public interface SearchContext {
-
- /**
- * Get active search
- *
- * @return
- */
- Search getSearch();
-
- /**
- * Test is named parameter exits
- *
- * @param key
- * @return
- */
- boolean containsKey(Object key);
-
- /**
- * Return named parameter
- *
- * @param key
- * @return
- */
- String getParameter(Object key);
-
- /**
- * Put parameter to context
- * @param key
- * @param value
- * @return
- */
- void setParameter(Object key, Object value);
-
- /**
- * Return named object
- *
- * @param key
- * @return
- */
- Object get(Object key);
-
- /**
- * Return active Preferences
- *
- * @return
- */
- Preferences getPreferences();
-
- /**
- * Return active SearchForm
- *
- * @return
- */
- SearchForm getSearchForm();
-
- /**
- * Return active Configuration
- *
- * @return
- */
- Configuration getConfigiration();
-
-}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContextImpl.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContextImpl.java
deleted file mode 100644
index 2e7fe1aab..000000000
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchContextImpl.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2006 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.webapp.common;
-
-import java.util.HashMap;
-
-import org.apache.hadoop.conf.Configuration;
-
-/**
- * Default Implementation of
- *
- * @see SearchContext
- */
-public class SearchContextImpl extends HashMap implements SearchContext {
-
- private static final long serialVersionUID = 1L;
-
- ServiceLocator serviceLocator;
-
- /**
- * Constructs a SearchContextImpl object and initializes it with provided data
- *
- * @param search
- * the Search object this context belongs to
- * @param locator
- * Used ServiceLocator
- */
- SearchContextImpl(ServiceLocator locator) {
- super();
- this.serviceLocator = locator;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.nutch.webapp.common.SearchContext#getSearch()
- */
- public Search getSearch() {
- return serviceLocator.getSearch();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.nutch.webapp.common.SearchContext#getParameter(java.lang.Object)
- */
- public String getParameter(Object key) {
- return (String) get(key);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.nutch.webapp.common.SearchContext#getPreferences()
- */
- public Preferences getPreferences() {
- return serviceLocator.getPreferences();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.nutch.webapp.common.SearchContext#getSearchForm()
- */
- public SearchForm getSearchForm() {
- return serviceLocator.getSearchForm();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.nutch.webapp.common.SearchContext#getConfigiration()
- */
- public Configuration getConfigiration() {
- return serviceLocator.getConfiguration();
- }
-
- public void setParameter(Object key, Object value) {
- this.put(key,value);
- }
-}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java
index 751d1be57..ec95fb478 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java
@@ -266,7 +266,7 @@ public class SearchForm {
/**
* Returns a string usable in urls that contains all active parameters and
* their values, if submitted encoding does not work values are encoded with
- * default encoding.
+ * utf-8 encoding.
*
* @param encoding
* @return
@@ -292,8 +292,8 @@ public class SearchForm {
sb.append(URLEncoder.encode(kv.getKey(), encoding)).append("=").append(
URLEncoder.encode(kv.getValue(), encoding));
} else {
- sb.append(URLEncoder.encode(kv.getKey())).append("=").append(
- URLEncoder.encode(kv.getValue()));
+ sb.append(URLEncoder.encode(kv.getKey(),"utf-8")).append("=").append(
+ URLEncoder.encode(kv.getValue(), "utf-8"));
}
if (i.hasNext()) {
sb.append("&");
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java
index 5dacd0d41..f1a91280b 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java
@@ -78,5 +78,5 @@ public interface ServiceLocator {
public Search getSearch();
public Locale getLocale();
-
+
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java
index 4e2e253c5..f799c56a9 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java
@@ -135,4 +135,5 @@ public class WebappInstanceServiceLocator implements ServiceLocator {
public Locale getLocale() {
return getPreferences().getLocale(request);
}
+
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java
index 614bedae4..b41805cc4 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java
@@ -15,7 +15,7 @@
*/
package org.apache.nutch.webapp.extension;
-import org.apache.nutch.webapp.common.SearchContext;
+import org.apache.nutch.webapp.common.ServiceLocator;
/**
* Plugins extending this extension point are run after the actual
@@ -25,6 +25,6 @@ public interface PostSearchExtensionPoint {
public static final String X_POINT_ID=PostSearchExtensionPoint.class.getName();
- void doPostSearch(SearchContext context);
+ void doPostSearch(ServiceLocator locator);
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java
index 9aeb8d613..d10ffe869 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java
@@ -15,7 +15,7 @@
*/
package org.apache.nutch.webapp.extension;
-import org.apache.nutch.webapp.common.SearchContext;
+import org.apache.nutch.webapp.common.ServiceLocator;
/**
* Plugins extending this extension point are run before the actual
@@ -25,6 +25,6 @@ public interface PreSearchExtensionPoint {
public static final String X_POINT_ID=PreSearchExtensionPoint.class.getName();
- void doPreSearch(SearchContext context);
+ void doPreSearch(ServiceLocator locator);
}
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java
index 8573f88af..8aaf01ca6 100644
--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java
+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java
@@ -15,7 +15,7 @@
*/
package org.apache.nutch.webapp.extension;
-import org.apache.nutch.webapp.common.SearchContext;
+import org.apache.nutch.webapp.common.ServiceLocator;
/**
* Plugins extending this interface can provide logic that
@@ -26,6 +26,6 @@ public interface SearchExtensionPoint {
public static final String X_POINT_ID=SearchExtensionPoint.class.getName();
- void doSearch(SearchContext context);
+ void doSearch(ServiceLocator locator);
}