Adding FileBasedProhibitedFromSearch and related files and directories. NIHVIVO-2914
This commit is contained in:
parent
7e4cf9a5c7
commit
7928b3cf52
4 changed files with 93 additions and 3 deletions
23
webapp/ontologies/search/vitroSearchProhibited.n3
Normal file
23
webapp/ontologies/search/vitroSearchProhibited.n3
Normal file
|
@ -0,0 +1,23 @@
|
|||
# $This file is distributed under the terms of the license in /doc/license.txt$
|
||||
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix vitroDisplay: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix core: <http://vivoweb.org/ontology/core#> .
|
||||
@prefix example: <http://example/ns/> .
|
||||
|
||||
# All instances of a class can be excluded from the search index
|
||||
# by adding a vitroDisplay:excludeClass property between
|
||||
# vitroDisplay:SearchIndex and the URI of the class
|
||||
# that you would like to exclude.
|
||||
|
||||
# All .n3 files in this directory will be used to configure
|
||||
# the search exclusions. Only .n3 files will be loaded.
|
||||
#
|
||||
# If you would like to add classes to the
|
||||
# exclusions, add a file to this directory ending in .n3 with
|
||||
# N3 statements similar to this example.
|
||||
|
||||
# vitroDisplay:SearchIndex
|
||||
# rdf:type owl:Thing ;
|
||||
# vitroDisplay:excludeClass example:classToExclude ;
|
|
@ -0,0 +1,59 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
public class FileBasedProhibitedFromSearch extends ProhibitedFromSearch {
|
||||
|
||||
/**
|
||||
* Load all the .n3 files in dir, add them to a model and create
|
||||
* a ProhibitedFromSearch based on that model
|
||||
* @param URI of the search individual.
|
||||
* @param dir to find N3 files in.
|
||||
*/
|
||||
public FileBasedProhibitedFromSearch(String uri, File dir){
|
||||
super( uri, getModelFromDir(dir));
|
||||
}
|
||||
|
||||
public FileBasedProhibitedFromSearch(String URI, OntModel model) {
|
||||
super(URI, model);
|
||||
}
|
||||
|
||||
protected static OntModel getModelFromDir( File dir){
|
||||
if( dir == null )
|
||||
throw new IllegalStateException("Must pass a File to FileBasedProhibitedFromSearch");
|
||||
if( !dir.isDirectory() )
|
||||
throw new IllegalStateException("Parameter dir to FileBasedProhibitedFromSearch " +
|
||||
"must be a File object for a directory");
|
||||
if( !dir.canRead() )
|
||||
throw new IllegalStateException("Parameter dir to FileBasedProhibitedFromSearch must " +
|
||||
"be a directory that is readable, check premissions on " + dir.getAbsolutePath());
|
||||
|
||||
OntModel modelOnlyForPFS = ModelFactory.createOntologyModel();
|
||||
for( File file : dir.listFiles()){
|
||||
if( file.isFile()
|
||||
&& file.canRead()
|
||||
&& file.getName() != null
|
||||
&& file.getName().endsWith(".n3")){
|
||||
try{
|
||||
modelOnlyForPFS.read( new FileInputStream(file), null, "N3");
|
||||
}catch( Throwable th){
|
||||
log.warn("could not load file " +
|
||||
file.getAbsolutePath() + file.separator + file.getName(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( modelOnlyForPFS.size() == 0 ){
|
||||
log.warn("No class exclusion statements found.");
|
||||
}
|
||||
|
||||
|
||||
modelOnlyForPFS.write( System.out , "N3-PP");
|
||||
|
||||
return modelOnlyForPFS;
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ public class ProhibitedFromSearch implements ClassProhibitedFromSearch{
|
|||
private static final String queryForProhibitedClasses = "SELECT ?prohibited WHERE{" +
|
||||
"?searchConfig <" + DisplayVocabulary.EXCLUDE_CLASS + "> ?prohibited . }";
|
||||
|
||||
private static final Log log = LogFactory.getLog(ProhibitedFromSearch.class.getName());
|
||||
protected static final Log log = LogFactory.getLog(ProhibitedFromSearch.class.getName());
|
||||
|
||||
public ProhibitedFromSearch(String URI, OntModel model){
|
||||
this.ProhibitedFromSearchURI = URI;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -18,6 +19,7 @@ import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
|||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.DatasetFactory;
|
||||
import com.hp.hpl.jena.tdb.base.file.FileBase;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
|
@ -30,6 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.IndexConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.AdditionalURIsToIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.FileBasedProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearchImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForContextNodes;
|
||||
|
@ -84,8 +87,13 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
|
|||
modifiers.add(new ContextNodeFields(jenaOntModel));
|
||||
modifiers.add(new NameBoost());
|
||||
|
||||
IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument(
|
||||
new ProhibitedFromSearch(DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel),
|
||||
// setup probhibited froms earch based on N3 files in the
|
||||
// directory WEB-INF/ontologies/search
|
||||
File dir = new File(sce.getServletContext().getRealPath("/WEB-INF/ontologies/search"));
|
||||
ProhibitedFromSearch pfs = new FileBasedProhibitedFromSearch(DisplayVocabulary.SEARCH_INDEX_URI, dir);
|
||||
|
||||
IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument(
|
||||
pfs,
|
||||
new IndividualProhibitedFromSearchImpl(context),
|
||||
modifiers);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue