From a8a2b7a803797a6d8612b7e61c58a0e5a09bd8aa Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Thu, 29 Jan 2015 02:16:42 +0100 Subject: [PATCH] persistency for vocabulary facet switch --- htroot/Vocabulary_p.html | 2 -- htroot/Vocabulary_p.java | 8 +++--- .../net/yacy/cora/lod/vocabulary/Tagging.java | 2 -- source/net/yacy/search/Switchboard.java | 7 ++++++ source/net/yacy/server/serverSwitch.java | 25 +++++++++++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/htroot/Vocabulary_p.html b/htroot/Vocabulary_p.html index ebefb1060..a956a7499 100644 --- a/htroot/Vocabulary_p.html +++ b/htroot/Vocabulary_p.html @@ -107,8 +107,6 @@ To see a list of all APIs, please visit the -
-
this shall be a search facet (disable this for large vocabularies!)

Empty Vocabulary 
diff --git a/htroot/Vocabulary_p.java b/htroot/Vocabulary_p.java index ce62aae79..62b8d5950 100644 --- a/htroot/Vocabulary_p.java +++ b/htroot/Vocabulary_p.java @@ -74,7 +74,6 @@ public class Vocabulary_p { if (discoveruri == null) discoverobjectspace = ""; Map table = new LinkedHashMap(); File propFile = LibraryProvider.autotagging.getVocabularyFile(discovername); - final boolean isFacet = post.getBoolean("isFacet"); final boolean discoverNot = post.get("discovermethod", "").equals("none"); final boolean discoverFromPath = post.get("discovermethod", "").equals("path"); final boolean discoverFromTitle = post.get("discovermethod", "").equals("title"); @@ -185,7 +184,6 @@ public class Vocabulary_p { } } Tagging newvoc = new Tagging(discovername, propFile, discoverobjectspace, table); - newvoc.setFacet(isFacet); LibraryProvider.autotagging.addVocabulary(newvoc); vocabularyName = discovername; vocabulary = newvoc; @@ -234,7 +232,11 @@ public class Vocabulary_p { // check the isFacet property if (vocabulary != null && post.containsKey("set")) { - vocabulary.setFacet(post.getBoolean("isFacet")); + boolean isFacet = post.getBoolean("isFacet"); + vocabulary.setFacet(isFacet); + Set omit = env.getConfigSet("search.result.show.vocabulary.omit"); + if (isFacet) omit.remove(vocabularyName); else omit.add(vocabularyName); + env.setConfig("search.result.show.vocabulary.omit", omit); } } } catch (final IOException e) { diff --git a/source/net/yacy/cora/lod/vocabulary/Tagging.java b/source/net/yacy/cora/lod/vocabulary/Tagging.java index 535e71716..507cf8289 100644 --- a/source/net/yacy/cora/lod/vocabulary/Tagging.java +++ b/source/net/yacy/cora/lod/vocabulary/Tagging.java @@ -278,8 +278,6 @@ public class Tagging { public void setFacet(boolean isFacet) { this.isFacet = isFacet; - String omit = Switchboard.getSwitchboard().getConfig("search.result.show.vocabulary.omit", ""); - } public int size() { diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index db09708f1..53be77b38 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -101,6 +101,7 @@ import net.yacy.cora.federate.solr.connector.ShardSelection; import net.yacy.cora.federate.solr.connector.SolrConnector.LoadTimeURL; import net.yacy.cora.federate.solr.instance.RemoteInstance; import net.yacy.cora.federate.yacy.CacheStrategy; +import net.yacy.cora.lod.vocabulary.Tagging; import net.yacy.cora.order.Base64Order; import net.yacy.cora.order.Digest; import net.yacy.cora.order.NaturalOrder; @@ -385,6 +386,12 @@ public final class Switchboard extends serverSwitch { public void run() { Thread.currentThread().setName("LibraryProvider.initialize"); LibraryProvider.initialize(Switchboard.this.dictionariesPath); + // persistent Vocabulary Switch + Set omit = Switchboard.this.getConfigSet("search.result.show.vocabulary.omit"); + for (String o: omit) { + Tagging t = LibraryProvider.autotagging.getVocabulary(o); + if (t != null) t.setFacet(false); + } } }.start(); diff --git a/source/net/yacy/server/serverSwitch.java b/source/net/yacy/server/serverSwitch.java index 7ddfb3d74..a63fb760e 100644 --- a/source/net/yacy/server/serverSwitch.java +++ b/source/net/yacy/server/serverSwitch.java @@ -282,6 +282,19 @@ public class serverSwitch { } } + public void setConfig(final String key, final String[] value) { + StringBuilder sb = new StringBuilder(); + if (value != null) for (String s: value) sb.append(',').append(s); + setConfig(key, sb.length() > 0 ? sb.substring(1) : ""); + } + + public void setConfig(final String key, Set value) { + String[] a = new String[value.size()]; + int c = 0; + for (String s: value) a[c++] = s; + setConfig(key, a); + } + public void removeConfig(final String key) { this.configProps.remove(key); } @@ -410,6 +423,18 @@ public class serverSwitch { return CommonPattern.COMMA.split(this.getConfig(key, dflt)); } + /** + * get a configuration parameter set + * @param key + * @param dflt a default list + * @return a set of strings which had been separated by comma in the setting + */ + public Set getConfigSet(final String key) { + Set h = new LinkedHashSet<>(); + for (String s: getConfigArray(key, "")) {s = s.trim(); if (s.length() > 0) h.add(s.trim());} + return h; + } + /** * Create a File instance for a configuration setting specifying a path. *