Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
bundle initialization of search navigation plugins in separate handler class to allow to use navigator map in config servlets (without need to create a search event)
reger60160877f535
diff --git a/source/net/yacy/search/navigator/NavigatorPlugins.java b/source/net/yacy/search/navigator/NavigatorPlugins.javanew file mode 100644index 000000000..ad09a63ac--- /dev/null+++ b/source/net/yacy/search/navigator/NavigatorPlugins.java@@ -0,0 +1,95 @@+/**+ * NavigatorPlugins.java+ * (C) 2016 by reger24; https://github.com/reger24+ *+ * This is a part of YaCy, a peer-to-peer based web search engine+ *+ * LICENSE+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program.+ * If not, see <http://www.gnu.org/licenses/>.+ */+package net.yacy.search.navigator;++import java.util.LinkedHashMap;+import java.util.Map;+import net.yacy.crawler.CrawlSwitchboard;+import static net.yacy.search.query.SearchEvent.log;+import net.yacy.search.schema.CollectionSchema;++/**+ * Class to create and manipulate search navigator plugin list+ */+public class NavigatorPlugins {++ /**+ * Creates map of active search navigators from comma separated config string+ * @param navcfg comma separated string of navigator names+ * @return map key=navigatorname, value=navigator.plugin reference+ */+ static public Map<String, Navigator> initFromCfgString(final String navcfg) {++ LinkedHashMap<String, Navigator> navigatorPlugins = new LinkedHashMap<String, Navigator>();+ if (navcfg == null || navcfg.isEmpty()) return navigatorPlugins;+ String[] navnames = navcfg.split(",");+ for (String navname : navnames) {+ if (navname.contains("authors")) {+ navigatorPlugins.put("authors", new StringNavigator("Authors", CollectionSchema.author_sxt));+ }++ if (navname.contains("collections")) {+ RestrictedStringNavigator tmpnav = new RestrictedStringNavigator("Collection", CollectionSchema.collection_sxt);+ // exclude default internal collection names+ tmpnav.addForbidden("dht");+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_AUTOCRAWL_DEEP);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_AUTOCRAWL_SHALLOW);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_PROXY);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_REMOTE);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_GREEDY_LEARNING_TEXT);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA);+ tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SURROGATE);+ navigatorPlugins.put("collections", tmpnav);+ }++ if (navname.contains("namespace")) {+ navigatorPlugins.put("namespace", new NameSpaceNavigator("Wiki Name Space"));+ }++ // YearNavigator with possible def of :fieldname:title in configstring+ if (navname.contains("year")) {+ if ((navname.indexOf(':')) > 0) { // example "year:dates_in_content_dts:Events"+ String[] navfielddef = navname.split(":");+ try {+ // year:fieldname:title+ CollectionSchema field = CollectionSchema.valueOf(navfielddef[1]);+ if (navfielddef.length > 2) {+ navigatorPlugins.put(navfielddef[1], new YearNavigator(navfielddef[2], field));+ } else {+ navigatorPlugins.put(navfielddef[1], new YearNavigator("Year-" + navfielddef[1], field));+ }+ } catch (java.lang.IllegalArgumentException ex) {+ log.severe("wrong navigator name in config: \"" + navname + "\" " + ex.getMessage());+ }+ } else { // "year" only use default last_modified+ navigatorPlugins.put("year", new YearNavigator("Year", CollectionSchema.last_modified));+ }+ }+ }+ return navigatorPlugins;+ }++}diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.javaindex 7dc1145be..7cc76d4c0 100644--- a/source/net/yacy/search/query/SearchEvent.java+++ b/source/net/yacy/search/query/SearchEvent.java@@ -68,7 +68,6 @@ import net.yacy.cora.sorting.WeakPriorityBlockingQueue.ReverseElement;import net.yacy.cora.storage.HandleSet;import net.yacy.cora.util.ConcurrentLog;import net.yacy.cora.util.SpaceExceededException;-import net.yacy.crawler.CrawlSwitchboard;import net.yacy.crawler.retrieval.Response;import net.yacy.data.WorkTables;import net.yacy.document.LargeNumberCache;@@ -98,11 +97,8 @@ import net.yacy.search.EventTracker;import net.yacy.search.Switchboard;import net.yacy.search.SwitchboardConstants;import net.yacy.search.index.Segment;-import net.yacy.search.navigator.NameSpaceNavigator;import net.yacy.search.navigator.Navigator;-import net.yacy.search.navigator.RestrictedStringNavigator;-import net.yacy.search.navigator.StringNavigator;-import net.yacy.search.navigator.YearNavigator;+import net.yacy.search.navigator.NavigatorPlugins;import net.yacy.search.ranking.ReferenceOrder;import net.yacy.search.schema.CollectionConfiguration;import net.yacy.search.schema.CollectionSchema;@@ -270,51 +266,7 @@ public final class SearchEvent {this.languageNavigator = navcfg.contains("language") ? new ConcurrentScoreMap<String>() : null;this.vocabularyNavigator = new TreeMap<String, ScoreMap<String>>();// prepare configured search navigation (plugins)- this.navigatorPlugins = new LinkedHashMap<String, Navigator>();- String[] navnames = navcfg.split(",");- for (String navname : navnames) {- if (navname.contains("authors")) {- this.navigatorPlugins.put("authors", new StringNavigator("Authors", CollectionSchema.author_sxt));- }- if (navname.contains("collections")) {- RestrictedStringNavigator tmpnav = new RestrictedStringNavigator("Collection", CollectionSchema.collection_sxt);- // exclude default internal collection names- tmpnav.addForbidden("dht");- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_AUTOCRAWL_DEEP);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_AUTOCRAWL_SHALLOW);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_PROXY);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_REMOTE);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_GREEDY_LEARNING_TEXT);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA);- tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SURROGATE);- this.navigatorPlugins.put("collections", tmpnav);- }- if (navname.contains("namespace")) {- this.navigatorPlugins.put("namespace", new NameSpaceNavigator("Name Space"));- }- // YearNavigator with possible def of :fieldname:title in configstring- if (navname.contains("year")) {- if ((navname.indexOf(':')) > 0) { // example "year:dates_in_content_dts:Events"- String[] navfielddef = navname.split(":");- try {- // year:fieldname:title- CollectionSchema field = CollectionSchema.valueOf(navfielddef[1]);- if (navfielddef.length > 2) {- this.navigatorPlugins.put(navfielddef[1], new YearNavigator(navfielddef[2], field));- } else {- this.navigatorPlugins.put(navfielddef[1], new YearNavigator("Year-" + navfielddef[1], field));- }- } catch (java.lang.IllegalArgumentException ex) {- log.severe("wrong navigator name in config: \"" + navname + "\" " + ex.getMessage());- }- } else { // "year" only use default last_modified- this.navigatorPlugins.put("year", new YearNavigator("Year", CollectionSchema.last_modified));- }- }- }+ this.navigatorPlugins = NavigatorPlugins.initFromCfgString(navcfg);this.snippets = new ConcurrentHashMap<String, LinkedHashSet<String>>();this.secondarySearchSuperviser = (this.query.getQueryGoal().getIncludeHashes().size() > 1) ? new SecondarySearchSuperviser(this) : null; // generate abstracts only for combined searches