Adding IndividualProhibitedFromSearchImpl( OntModel ) constructor. Refactoring SolrIndexer to move away from obj2Doc list.
This commit is contained in:
parent
74a5b665cb
commit
bbe6333ae4
4 changed files with 50 additions and 96 deletions
|
@ -28,6 +28,10 @@ public class IndividualProhibitedFromSearchImpl implements IndividualProhibitedF
|
|||
this.fullModel = ModelContext.getUnionOntModelSelector(context).getFullModel();
|
||||
}
|
||||
|
||||
public IndividualProhibitedFromSearchImpl( OntModel fullModel ){
|
||||
this.fullModel = fullModel;
|
||||
}
|
||||
|
||||
public boolean isIndividualProhibited(String uri){
|
||||
if( uri == null || uri.isEmpty() )
|
||||
return true;
|
||||
|
|
|
@ -28,7 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.ClassProhibitedFromSearch;
|
|||
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
||||
|
||||
public class IndividualToSolrDocument implements Obj2DocIface {
|
||||
public class IndividualToSolrDocument {
|
||||
|
||||
protected LuceneDocToSolrDoc luceneToSolr;
|
||||
|
||||
|
@ -70,21 +70,15 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
public Object translate(Object obj) throws IndexingException{
|
||||
long tProhibited = System.currentTimeMillis();
|
||||
|
||||
if(!(obj instanceof Individual))
|
||||
return null;
|
||||
|
||||
Individual ent = (Individual)obj;
|
||||
public SolrInputDocument translate(Individual ind) throws IndexingException{
|
||||
long tProhibited = System.currentTimeMillis();
|
||||
String value;
|
||||
StringBuffer classPublicNames = new StringBuffer();
|
||||
classPublicNames.append("");
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
|
||||
//DocId
|
||||
String id = ent.getURI();
|
||||
String id = ind.getURI();
|
||||
log.debug("translating " + id);
|
||||
|
||||
if(id == null){
|
||||
|
@ -107,7 +101,7 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
|
||||
// Types and classgroups
|
||||
boolean prohibited = false;
|
||||
List<VClass> vclasses = ent.getVClasses(false);
|
||||
List<VClass> vclasses = ind.getVClasses(false);
|
||||
superClassNames = new ArrayList<String>();
|
||||
String superLclName = null;
|
||||
long tClassgroup = System.currentTimeMillis();
|
||||
|
@ -170,22 +164,22 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
doc.addField(term.JCLASS, entClassName);
|
||||
|
||||
//Individual Label
|
||||
if(ent.getRdfsLabel() != null)
|
||||
value = ent.getRdfsLabel();
|
||||
if(ind.getRdfsLabel() != null)
|
||||
value = ind.getRdfsLabel();
|
||||
else{
|
||||
log.debug("Using local name for individual with rdfs:label " + ent.getURI());
|
||||
value = ent.getLocalName();
|
||||
log.debug("Using local name for individual with rdfs:label " + ind.getURI());
|
||||
value = ind.getLocalName();
|
||||
}
|
||||
|
||||
// collecting object property statements
|
||||
|
||||
String uri = ent.getURI();
|
||||
String uri = ind.getURI();
|
||||
StringBuffer objectNames = new StringBuffer();
|
||||
objectNames.append("");
|
||||
String t=null;
|
||||
addUri = new StringBuffer();
|
||||
addUri.append("");
|
||||
List<ObjectPropertyStatement> objectPropertyStatements = ent.getObjectPropertyStatements();
|
||||
List<ObjectPropertyStatement> objectPropertyStatements = ind.getObjectPropertyStatements();
|
||||
if (objectPropertyStatements != null) {
|
||||
Iterator<ObjectPropertyStatement> objectPropertyStmtIter = objectPropertyStatements.iterator();
|
||||
while (objectPropertyStmtIter.hasNext()) {
|
||||
|
@ -222,14 +216,14 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
|
||||
if(documentModifiers == null){
|
||||
//boost for entity
|
||||
if(ent.getSearchBoost() != null && ent.getSearchBoost() != 0)
|
||||
doc.setDocumentBoost(ent.getSearchBoost());
|
||||
if(ind.getSearchBoost() != null && ind.getSearchBoost() != 0)
|
||||
doc.setDocumentBoost(ind.getSearchBoost());
|
||||
}
|
||||
|
||||
//thumbnail
|
||||
try{
|
||||
value = null;
|
||||
if(ent.hasThumb())
|
||||
if(ind.hasThumb())
|
||||
doc.addField(term.THUMBNAIL, "1");
|
||||
else
|
||||
doc.addField(term.THUMBNAIL, "0");
|
||||
|
@ -253,13 +247,13 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
StringBuffer allTextValue = new StringBuffer();
|
||||
allTextValue.append("");
|
||||
allTextValue.append(" ");
|
||||
allTextValue.append(((t=ent.getName()) == null)?"":t);
|
||||
allTextValue.append(((t=ind.getName()) == null)?"":t);
|
||||
allTextValue.append(" ");
|
||||
allTextValue.append(((t=ent.getAnchor()) == null)?"":t);
|
||||
allTextValue.append(((t=ind.getAnchor()) == null)?"":t);
|
||||
allTextValue.append(" ");
|
||||
allTextValue.append(classPublicNames.toString());
|
||||
|
||||
List<DataPropertyStatement> dataPropertyStatements = ent.getDataPropertyStatements();
|
||||
List<DataPropertyStatement> dataPropertyStatements = ind.getDataPropertyStatements();
|
||||
if (dataPropertyStatements != null) {
|
||||
Iterator<DataPropertyStatement> dataPropertyStmtIter = dataPropertyStatements.iterator();
|
||||
while (dataPropertyStmtIter.hasNext()) {
|
||||
|
@ -282,7 +276,7 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
if( documentModifiers != null ){
|
||||
doc.addField(term.targetInfo,"");
|
||||
for(DocumentModifier modifier: documentModifiers){
|
||||
modifier.modifyDocument(ent, doc);
|
||||
modifier.modifyDocument(ind, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,37 +284,12 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
|||
return doc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public IndividualToSolrDocument(Entity2LuceneDoc e2d){
|
||||
//// entityToLucene = e2d;
|
||||
// luceneToSolr = new LuceneDocToSolrDoc();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean canTranslate(Object obj) {
|
||||
return obj != null && obj instanceof Individual;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnTranslate(Object result) {
|
||||
return result != null && result instanceof SolrDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Object getIndexId(Object obj) {
|
||||
throw new Error("IndiviudalToSolrDocument.getIndexId() is unimplemented");
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Object translate(Object obj) throws IndexingException {
|
||||
// return luceneToSolr.translate( entityToLucene.translate( obj ) );
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Object unTranslate(Object result) {
|
||||
public Individual unTranslate(Object result) {
|
||||
Individual ent = null;
|
||||
if( result != null && result instanceof Document){
|
||||
Document hit = (Document) result;
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -15,7 +14,6 @@ import org.apache.solr.client.solrj.SolrServer;
|
|||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.response.UpdateResponse;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.SolrException;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
||||
|
@ -26,20 +24,20 @@ public class SolrIndexer implements IndexerIface {
|
|||
private final static Log log = LogFactory.getLog(SolrIndexer.class);
|
||||
|
||||
protected SolrServer server;
|
||||
protected boolean indexing;
|
||||
protected List<Obj2DocIface> obj2DocList;
|
||||
protected HashSet<String> urisIndexed;
|
||||
protected boolean indexing;
|
||||
protected HashSet<String> urisIndexed;
|
||||
protected IndividualToSolrDocument individualToSolrDoc;
|
||||
|
||||
public SolrIndexer( SolrServer server, List<Obj2DocIface> o2d){
|
||||
public SolrIndexer( SolrServer server, IndividualToSolrDocument indToDoc){
|
||||
this.server = server;
|
||||
this.obj2DocList = o2d;
|
||||
this.individualToSolrDoc = indToDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void index(Individual ind, boolean newDoc) throws IndexingException {
|
||||
if( ! indexing )
|
||||
throw new IndexingException("SolrIndexer: must call " +
|
||||
"startIndexing() before index().");
|
||||
"startIndexing() before index().");
|
||||
|
||||
if( ind == null )
|
||||
log.debug("Individual to index was null, ignoring.");
|
||||
|
@ -50,40 +48,26 @@ public class SolrIndexer implements IndexerIface {
|
|||
return;
|
||||
}else{
|
||||
urisIndexed.add(ind.getURI());
|
||||
log.debug("indexing " + ind.getURI());
|
||||
Iterator<Obj2DocIface> it = getObj2DocList().iterator();
|
||||
while (it.hasNext()) {
|
||||
Obj2DocIface obj2doc = (Obj2DocIface) it.next();
|
||||
if (obj2doc.canTranslate(ind)) {
|
||||
SolrInputDocument solrDoc = (SolrInputDocument) obj2doc.translate(ind);
|
||||
if( solrDoc != null){
|
||||
//sending each doc individually is inefficient
|
||||
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
|
||||
docs.add( solrDoc );
|
||||
UpdateResponse res = server.add( docs );
|
||||
log.debug("response after adding docs to server: "+ res);
|
||||
|
||||
|
||||
// if( !newDoc ){
|
||||
// server.add( docs );
|
||||
// log.debug("updated " + ind.getName() + " " + ind.getURI());
|
||||
// }else{
|
||||
// server.add( docs );
|
||||
// log.debug("added " + ind.getName() + " " + ind.getURI());
|
||||
// }
|
||||
}else{
|
||||
log.debug("removing from index " + ind.getURI());
|
||||
//writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("indexing " + ind.getURI());
|
||||
|
||||
SolrInputDocument solrDoc = individualToSolrDoc.translate(ind);
|
||||
if( solrDoc != null){
|
||||
//sending each doc individually is inefficient
|
||||
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
|
||||
docs.add( solrDoc );
|
||||
UpdateResponse res = server.add( docs );
|
||||
log.debug("response after adding docs to server: "+ res);
|
||||
}else{
|
||||
log.debug("removing from index " + ind.getURI());
|
||||
//TODO: how do we delete document?
|
||||
//writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new IndexingException(ex.getMessage());
|
||||
} catch (SolrServerException ex) {
|
||||
throw new IndexingException(ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,12 +102,12 @@ public class SolrIndexer implements IndexerIface {
|
|||
|
||||
|
||||
public synchronized void addObj2Doc(Obj2DocIface o2d) {
|
||||
if (o2d != null)
|
||||
obj2DocList.add(o2d);
|
||||
//no longer used
|
||||
}
|
||||
|
||||
public synchronized List<Obj2DocIface> getObj2DocList() {
|
||||
return obj2DocList;
|
||||
//no longer used
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
|
|||
import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearchImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
|
||||
|
@ -74,12 +73,10 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
|
|||
IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument(
|
||||
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
|
||||
new IndividualProhibitedFromSearchImpl(context),
|
||||
modifiers);
|
||||
List<Obj2DocIface> o2d = new ArrayList<Obj2DocIface>();
|
||||
o2d.add(indToSolrDoc);
|
||||
modifiers);
|
||||
|
||||
/* setup solr indexer */
|
||||
SolrIndexer solrIndexer = new SolrIndexer(server, o2d);
|
||||
SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc);
|
||||
if( solrIndexer.isIndexEmpty() ){
|
||||
log.info("solr index is empty, requesting rebuild");
|
||||
sce.getServletContext().setAttribute(LuceneSetup.INDEX_REBUILD_REQUESTED_AT_STARTUP, Boolean.TRUE);
|
||||
|
|
Loading…
Add table
Reference in a new issue