Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

refactor namespace navigator as part of navigatorplugin map, this allows the navigator to include counts all matches (rwi+fulltext). Fixing also unresolved_pattern in navigators title (of the counter) The use of inurl: query modifier as filter has not been changed keeping it as soft (unsharp) filter facet.

reger3d1d29730841
diff --git a/htroot/yacysearchtrailer.html b/htroot/yacysearchtrailer.html
index 631846e52..38173adf1 100644
--- a/htroot/yacysearchtrailer.html
+++ b/htroot/yacysearchtrailer.html
@@ -181,15 +181,6 @@ function toggleVisibility(name, count) {
<script>if (#[count]# <= 8) toggleVisibility('languages', #[count]#);</script>
#(/nav-languages)#
-#(nav-namespace)#::
-<ul class="nav nav-sidebar menugroup">
-<li style="cursor: pointer; cursor: hand;"><h3 onclick="toggleVisibility('namespace', #[count]#);">Name Space [#[count]#] <span style="float:right" id="chevron-namespace" class="glyphicon glyphicon-chevron-down" title="click to expand facet"></span></h3></li>
-#{element}#
-<li style="display:none" id="#[id]#"><a href="#[url]#" class="MenuItemLink"><input type="checkbox" onchange="window.location.href='#[url]#'"#(on)# checked="checked"::#(/on)#/> #[name]# (#[count]#)</a></li>
-#{/element}#</ul>
-<script>if (#[count]# <= 8) toggleVisibility('namespace', #[count]#);</script>
-#(/nav-namespace)#
-
#{navs}#
<ul class="nav nav-sidebar menugroup">
<li style="cursor: pointer; cursor: hand;"><h3 onclick="toggleVisibility('#[name]#', #[count]#);">#[displayname]# [#[count]#] <span style="float:right" id="chevron-#[name]#" class="glyphicon glyphicon-chevron-down" title="click to expand facet"></span></h3></li>
diff --git a/htroot/yacysearchtrailer.java b/htroot/yacysearchtrailer.java
index 51c6182d8..77039f390 100644
--- a/htroot/yacysearchtrailer.java
+++ b/htroot/yacysearchtrailer.java
@@ -99,48 +99,9 @@ public class yacysearchtrailer {
prop.put("searchdomswitches_searchimage_check", (contentdom == ContentDomain.IMAGE) ? "1" : "0");
prop.put("searchdomswitches_searchapp_check", (contentdom == ContentDomain.APP) ? "1" : "0");
- // namespace navigators
String name;
int count;
Iterator<String> navigatorIterator;
- if (theSearch.namespaceNavigator == null || theSearch.namespaceNavigator.isEmpty()) {
- prop.put("nav-namespace", 0);
- } else {
- prop.put("nav-namespace", 1);
- navigatorIterator = theSearch.namespaceNavigator.keys(false);
- int i = 0, pos = 0, neg = 0;
- String nav, rawNav;
- while (i < QueryParams.FACETS_STANDARD_MAXCOUNT && navigatorIterator.hasNext()) {
- name = navigatorIterator.next();
- count = theSearch.namespaceNavigator.get(name);
- if (count == 0) break;
- nav = "inurl%3A" + name;
- /* Avoid double percent encoding in QueryParams.navurl */
- rawNav = "inurl:" + name;
- if (!theSearch.query.modifier.toString().contains("inurl:"+name)) {
- pos++;
- prop.put("nav-namespace_element_" + i + "_on", 1);
- prop.put(fileType, "nav-namespace_element_" + i + "_modifier", nav);
- } else {
- neg++;
- prop.put("nav-namespace_element_" + i + "_on", 0);
- prop.put(fileType, "nav-namespace_element_" + i + "_modifier", "-" + nav);
- nav="";
- rawNav = "";
- }
- prop.put(fileType, "nav-namespace_element_" + i + "_name", name);
- /* URL is already percent encoded : no need to re-encode specifically for the file type */
- prop.put("nav-namespace_element_" + i + "_url", QueryParams.navurl(fileType, 0, theSearch.query, rawNav, false).toString());
- prop.put(fileType, "nav-namespace_element_" + i + "_id", "namespace_" + i);
- prop.put("nav-namespace_element_" + i + "_count", count);
- prop.put("nav-namespace_element_" + i + "_nl", 1);
- i++;
- }
- prop.put("nav-namespace_element", i);
- i--;
- prop.put("nav-namespace_element_" + i + "_nl", 0);
- if (pos == 1 && neg == 0) prop.put("nav-namespace", 0); // this navigation is not useful
- }
// domain navigators
final ScoreMap<String> hostNavigator = theSearch.hostNavigator;
diff --git a/source/net/yacy/search/navigator/NameSpaceNavigator.java b/source/net/yacy/search/navigator/NameSpaceNavigator.java
new file mode 100644
index 000000000..df3680b88
--- /dev/null
+++ b/source/net/yacy/search/navigator/NameSpaceNavigator.java
@@ -0,0 +1,65 @@
+/**
+ * NameSpaceNavigator.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.List;
+import net.yacy.kelondro.data.meta.URIMetadataNode;
+
+/**
+ * Navigator for name space used in some wikies by using a : (colon) in the path
+ * e.g. http://wikiurl/Help:About counted as name space = Help
+ * (remark: the query uses the inurl: modifier (without the trailing : ) to filter results which matches http://host/Help.html too)
+ */
+public class NameSpaceNavigator extends StringNavigator implements Navigator {
+
+ public NameSpaceNavigator(String title) {
+ super(title, null);
+ }
+
+ @Override
+ public String getQueryModifier() {
+ return "inurl:";
+ }
+
+ @Override
+ public void incDocList(List<URIMetadataNode> docs) {
+ // we need to override, as StringNavigator expects a field definition
+ for (URIMetadataNode doc : docs) {
+ incDoc(doc);
+ }
+ }
+
+ @Override
+ public void incDoc(URIMetadataNode doc) {
+ int p;
+ String pagepath = doc.url().getPath();
+ if ((p = pagepath.indexOf(':')) >= 0) {
+ pagepath = pagepath.substring(0, p);
+ p = pagepath.lastIndexOf('/');
+ if (p >= 0) {
+ pagepath = pagepath.substring(p + 1);
+ this.inc(pagepath);
+ }
+ }
+ }
+}
diff --git a/source/net/yacy/search/navigator/StringNavigator.java b/source/net/yacy/search/navigator/StringNavigator.java
index 6bebfbf53..dad850c4b 100644
--- a/source/net/yacy/search/navigator/StringNavigator.java
+++ b/source/net/yacy/search/navigator/StringNavigator.java
@@ -22,10 +22,8 @@
*/
package net.yacy.search.navigator;
-import java.util.Date;
import java.util.List;
import java.util.Map;
-import net.yacy.cora.federate.solr.SolrType;
import net.yacy.cora.sorting.ConcurrentScoreMap;
import net.yacy.cora.sorting.ReversibleScoreMap;
import net.yacy.kelondro.data.meta.URIMetadataNode;
@@ -84,7 +82,7 @@ public class StringNavigator extends ConcurrentScoreMap<String> implements Navi
mod = ":";
}
} else {
- mod = ":";
+ mod = "";
}
return mod;
}
@@ -111,21 +109,17 @@ public class StringNavigator extends ConcurrentScoreMap<String> implements Navi
@Override
public void incDoc(URIMetadataNode doc) {
if (field != null) {
- if (field.getType() == SolrType.date) {
- Date dd = (Date) doc.getFieldValue(field.getSolrFieldName());
- String year = Integer.toString(dd.getYear() + 1900);
- this.inc(year);
- } else {
- Object val = doc.getFieldValue(field.getSolrFieldName());
- if (val instanceof List) {
- List<String> ll = (List) val;
- for (String s : ll) {
+ Object val = doc.getFieldValue(field.getSolrFieldName());
+ if (val instanceof List) {
+ List<String> ll = (List) val;
+ for (String s : ll) {
+ if (!s.isEmpty()) {
this.inc(s);
}
- } else {
- if (val != null) {
- this.inc((String) val);
- }
+ }
+ } else {
+ if (val != null) {
+ this.inc((String) val);
}
}
}
diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.java
index 4122e1126..ae995a620 100644
--- a/source/net/yacy/search/query/SearchEvent.java
+++ b/source/net/yacy/search/query/SearchEvent.java
@@ -98,6 +98,7 @@ 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;
@@ -148,7 +149,6 @@ public final class SearchEvent {
private final AtomicInteger expectedRemoteReferences, maxExpectedRemoteReferences; // counter for referenced that had been sorted out for other reasons
public final ScoreMap<String> locationNavigator; // a counter for the appearance of location coordinates
public final ScoreMap<String> hostNavigator; // a counter for the appearance of host names
- public final ScoreMap<String> namespaceNavigator; // a counter for name spaces
public final ScoreMap<String> protocolNavigator; // a counter for protocol types
public final ScoreMap<String> filetypeNavigator; // a counter for file types
public final ScoreMap<String> dateNavigator; // a counter for file types
@@ -261,7 +261,6 @@ public final class SearchEvent {
// prepare configured search navigation
final String navcfg = Switchboard.getSwitchboard().getConfig("search.navigation", "");
this.locationNavigator = navcfg.contains("location") ? new ConcurrentScoreMap<String>() : null;
- this.namespaceNavigator = navcfg.contains("namespace") ? new ConcurrentScoreMap<String>() : null;
this.hostNavigator = navcfg.contains("hosts") ? new ConcurrentScoreMap<String>() : null;
this.protocolNavigator = navcfg.contains("protocol") ? new ConcurrentScoreMap<String>() : null;
this.filetypeNavigator = navcfg.contains("filetype") ? new ConcurrentScoreMap<String>() : null;
@@ -292,6 +291,9 @@ public final class SearchEvent {
tmpnav.addForbidden("robot_" + CrawlSwitchboard.CRAWL_PROFILE_SURROGATE);
this.navigatorPlugins.put("collections", tmpnav);
}
+ if (navname.contains("namespace")) {
+ this.navigatorPlugins.put("namespace", new NameSpaceNavigator("Name Space"));
+ }
}
this.snippets = new ConcurrentHashMap<String, LinkedHashSet<String>>();
@@ -1342,19 +1344,6 @@ public final class SearchEvent {
}
}
- // namespace navigation
- if (this.namespaceNavigator != null) {
- String pagepath = page.url().getPath();
- if ((p = pagepath.indexOf(':')) >= 0) {
- pagepath = pagepath.substring(0, p);
- p = pagepath.lastIndexOf('/');
- if (p >= 0) {
- pagepath = pagepath.substring(p + 1);
- this.namespaceNavigator.inc(pagepath);
- }
- }
- }
-
return page; // accept url
}
return null;