Prepared the first basic navigators (for authors and collections) for the list of SearchEvent.navigatorPlugins and adjusted servlet to use these. - this allows to configure display order of these navigators (by ordering config string) - eventually allows for additional and/or custom navigators using any available index field without need for changing servlets - the Collection navigation has been adjusted to exclude the internal, default robot_* and dht collections from displaying - rwi results are now also checked for navigatior by the refactored navi's So far no config options were added to customize or add navigators (may come later if route of upcoming modularization/plugin system is defined).pull/93/head
parent
fd3f58fcaa
commit
5eb3ee4e20
@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
* Navigator.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 java.util.Map;
|
||||||
|
import net.yacy.cora.sorting.ReversibleScoreMap;
|
||||||
|
import net.yacy.cora.sorting.ScoreMap;
|
||||||
|
import net.yacy.kelondro.data.meta.URIMetadataNode;
|
||||||
|
import net.yacy.search.query.QueryModifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for search navigators used in search servlets to restrict displayed
|
||||||
|
* search results.
|
||||||
|
*/
|
||||||
|
public interface Navigator extends ScoreMap<String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return name of the navigator for display in ui
|
||||||
|
*/
|
||||||
|
public String getDisplayName() ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form of the element (e.g. for languages the key might be "en",
|
||||||
|
* the display form "English"
|
||||||
|
*
|
||||||
|
* @param key original key as counted in this navigator
|
||||||
|
* @return a translated display text for a key
|
||||||
|
*/
|
||||||
|
public String getElementDisplayName(String key) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the query modifier prefix. This is used (needed) within the servlet
|
||||||
|
* to create a new modifier for a activated (clicked) navigator item.
|
||||||
|
*
|
||||||
|
* @return the query modifier prefix (if any, eg. "filetype:" or "author:" )
|
||||||
|
*/
|
||||||
|
public String getQueryModifier() ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add counts for this navigator from documents in the provided list.
|
||||||
|
* The navigator looks for a field in the document and increases the counts
|
||||||
|
* depending on the value in the document field.
|
||||||
|
*
|
||||||
|
* @param docs list of documents
|
||||||
|
*/
|
||||||
|
public void incDocList(List<URIMetadataNode> docs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add count for this navigator from provided Solr facet map.
|
||||||
|
* The navigator looks for a field in the facet map and increases the counts
|
||||||
|
* by the value in the facet map.
|
||||||
|
*
|
||||||
|
* @param facets Solr facets
|
||||||
|
*/
|
||||||
|
public void incFacet(Map<String, ReversibleScoreMap<String>> facets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add count for this navigator from provided document.
|
||||||
|
* The navigator looks for a field in the document and increases the counts
|
||||||
|
* depending on the value in the document field.
|
||||||
|
*
|
||||||
|
* @param docs document
|
||||||
|
*/
|
||||||
|
public void incDoc(URIMetadataNode doc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper routine to determine if current navigator key is part of the query
|
||||||
|
* modifier (is active)
|
||||||
|
*
|
||||||
|
* @param modifier current search query modifier
|
||||||
|
* @param name the navigator key to check
|
||||||
|
* @return true if navigator key is mentioned as modifier
|
||||||
|
*/
|
||||||
|
public boolean modifieractive(QueryModifier modifier, String name);
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
/**
|
||||||
|
* RestrictedStringNavigator.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.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import net.yacy.cora.sorting.ScoreMap;
|
||||||
|
import net.yacy.search.schema.CollectionSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Navigator that allows to restrict the items
|
||||||
|
* If allowed items are set only these will be counted or displayed
|
||||||
|
* If forbidden items are set these are excluded from display
|
||||||
|
*/
|
||||||
|
public class RestrictedStringNavigator extends StringNavigator implements Navigator {
|
||||||
|
|
||||||
|
Set<String> allowed; // complete list of keys, if empty all keys are allowed
|
||||||
|
Set<String> forbidden; // keys to exclude
|
||||||
|
|
||||||
|
public RestrictedStringNavigator(String title, CollectionSchema field) {
|
||||||
|
super(title, field);
|
||||||
|
this.allowed = new HashSet<String>();
|
||||||
|
this.forbidden = new HashSet<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a allowed navigator key string. If set, only allowed items are displayed
|
||||||
|
* which means you have to add all possible key which sall be allowed.
|
||||||
|
*
|
||||||
|
* @param s key
|
||||||
|
* @return true if added, false if already existed
|
||||||
|
*/
|
||||||
|
public boolean addAllowed(String s) {
|
||||||
|
return this.allowed.add(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a blacklisted item which shall be excluded from counting and display.
|
||||||
|
*
|
||||||
|
* @param s key
|
||||||
|
* @return true if added, false if already existed
|
||||||
|
*/
|
||||||
|
public boolean addForbidden(String s) {
|
||||||
|
return this.forbidden.add(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase counter if item allowed and not forbidden
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void inc(final String key) {
|
||||||
|
if (!forbidden.contains(key)) {
|
||||||
|
if (allowed.isEmpty()) {
|
||||||
|
super.inc(key);
|
||||||
|
} else if (allowed.contains(key)) {
|
||||||
|
super.inc(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase counter if item allowed and not forbidden
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void inc(ScoreMap<String> map) {
|
||||||
|
if (map == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String entry : map) {
|
||||||
|
if (!forbidden.contains(entry)) {
|
||||||
|
if (allowed.isEmpty()) {
|
||||||
|
int count = map.get(entry);
|
||||||
|
if (count > 0) {
|
||||||
|
this.inc(entry, count);
|
||||||
|
}
|
||||||
|
} else if (allowed.contains(entry)) {
|
||||||
|
int count = map.get(entry);
|
||||||
|
if (count > 0) {
|
||||||
|
this.inc(entry, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,141 @@
|
|||||||
|
/**
|
||||||
|
* Navigator.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.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;
|
||||||
|
import net.yacy.search.query.QueryModifier;
|
||||||
|
import net.yacy.search.schema.CollectionSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StringNavigator extends ConcurrentScoreMap<String> implements Navigator {
|
||||||
|
|
||||||
|
public String title;
|
||||||
|
public CollectionSchema field;
|
||||||
|
|
||||||
|
public StringNavigator(String title, CollectionSchema field) {
|
||||||
|
super();
|
||||||
|
this.title = title;
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementDisplayName(String e) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQueryModifier() {
|
||||||
|
String mod;
|
||||||
|
if (field != null) {
|
||||||
|
switch (field) {
|
||||||
|
case author_sxt:
|
||||||
|
mod = "author:";
|
||||||
|
break;
|
||||||
|
case url_protocol_s:
|
||||||
|
mod = "/";
|
||||||
|
break;
|
||||||
|
case url_file_ext_s:
|
||||||
|
mod = "filetype:";
|
||||||
|
break;
|
||||||
|
case collection_sxt:
|
||||||
|
mod = "collection:";
|
||||||
|
break;
|
||||||
|
case host_s:
|
||||||
|
mod = "site:";
|
||||||
|
break;
|
||||||
|
case language_s:
|
||||||
|
mod = "/language/";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mod = ":";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mod = ":";
|
||||||
|
}
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void incDocList(List<URIMetadataNode> docs) {
|
||||||
|
if (field != null) {
|
||||||
|
for (URIMetadataNode doc : docs) {
|
||||||
|
incDoc(doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void incFacet(Map<String, ReversibleScoreMap<String>> facets) {
|
||||||
|
if (field != null && facets != null && !facets.isEmpty()) {
|
||||||
|
ReversibleScoreMap<String> fcts = facets.get(field.getSolrFieldName());
|
||||||
|
if (fcts != null) {
|
||||||
|
this.inc(fcts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
this.inc(s);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (val != null) {
|
||||||
|
this.inc((String) val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean modifieractive(QueryModifier modifier, String name) {
|
||||||
|
if (name.indexOf(' ') < 0) {
|
||||||
|
return modifier.toString().contains(getQueryModifier() + name);
|
||||||
|
} else {
|
||||||
|
return modifier.toString().contains(getQueryModifier() + "(" + name + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue