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